Hooded Plover Nest Survival

Exploration of dataset

Authors
Affiliations

Department of Ornithology, Max Planck Institute for Biological Intelligence, Germany

Lucinda Plowman

Coastal and Wetland Birds Program, BirdLife Australia

Grainne Maguire

Coastal and Wetland Birds Program, BirdLife Australia

Mike Weston

Life and Environmental Sciences, Deakin University, Australia

Published

March 4, 2024

Code
knitr::opts_chunk$set(cache = TRUE)

Prerequisites

R packages

  • The following packages are needed for analysis and can be easily installed from CRAN or GitHub by running the following code chunk:
Code
# a vector of all the packages needed in the project
packages_required_in_project <- c("tidyverse",
                                  "readxl",
                                  "RMark",
                                  "RColorBrewer",
                                  "patchwork",
                                  "mapview",
                                  "lubridate",
                                  "extrafont",
                                  "here",
                                  "DT",
                                  "leaflet",
                                  "sf",
                                  "leafpop",
                                  "tsibble",
                                  "corrplot",
                                  "gghalves",
                                  "gam",
                                  "pscl",
                                  "gamlss",
                                  "gt")
                                  
# of the required packages, check if some need to be installed
new.packages <- 
  packages_required_in_project[!(packages_required_in_project %in% 
                                   installed.packages()[,"Package"])]

# install all packages that are not locally available
if(length(new.packages)) install.packages(new.packages)

# load all the packages into the current R session
lapply(packages_required_in_project, require, character.only = TRUE)

# set the home directory to where the project is locally based (i.e., to find 
# the relevant datasets to import, etc.
here::set_here()

Plotting themes

  • The following plotting themes, colors, and typefaces are used throughout the project:
Code
# Find fonts from computer that you want. Use regular expressions to do this
# For example, load all fonts that are 'verdana' or 'Verdana'
extrafont::font_import(pattern = "[V/v]erdana", prompt = FALSE) 

# check which fonts were loaded
extrafont::fonts()
extrafont::fonttable()
extrafont::loadfonts() # load these into R

# define the plotting theme to be used in subsequent ggplots
luke_theme <- 
  theme_bw() +
  theme(
    text = element_text(family = "Verdana"),
    legend.title = element_text(size = 10),
    legend.text = element_text(size = 8),
    axis.title.x = element_text(size = 10),
    axis.text.x  = element_text(size = 8), 
    axis.title.y = element_text(size = 10),
    axis.text.y = element_text(size = 8),
    strip.text = element_text(size = 10),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.ticks = element_line(size = 0.5, colour = "grey40"),
    axis.ticks.length = unit(0.2, "cm"),
    panel.border = element_rect(linetype = "solid", colour = "grey"),
    legend.position = c(0.1, 0.9)
  )

region_names <- c(
  'FP' = "Fleurieu Peninsula",
  'MP' = "Mornington Peninsula",
  'BSC' = "Bellarine / Surf Coast")

# set mapview to show satellite imagery
# mapviewOptions(basemaps = c("Esri.WorldImagery"))

# # set plotting color palettes
# sex_pal2 <- 
#   c(pull(ggthemes_data$wsj$palettes$colors6[3,2]), 
#     pull(ggthemes_data$wsj$palettes$colors6[2,2]))
# 
# sex_pal3 <- 
#   c(pull(ggthemes_data$wsj$palettes$colors6[3,2]), 
#     pull(ggthemes_data$wsj$palettes$colors6[3,2]),
#     pull(ggthemes_data$wsj$palettes$colors6[2,2]),
#     pull(ggthemes_data$wsj$palettes$colors6[2,2]))
# 
# # specify the facet labels for each species and sex
# species_names <- c(
#   'BC' = "Black coucal",
#   'WBC' = "White-browed coucal")
# 
# sex_names <- c(
#   'female' = "Females",
#   'male' = "Males")
# 
# analysis_names <- c(
#   'male' = "Male Mo scenario",
#   'female' = "Female Mo scenario"
# )
# 
# # color of mean estimate point in forest plots
# col_all <- "#2E3440"
# 
# # custom color palette for the plotting of Juvenile and Adult stats
# cbPalette_LTRE <- 
#   c("#D9D9D9", "#D9D9D9", "#D9D9D9", 
#     "#D9D9D9", "#A6A6A6", "#A6A6A6",
#     "#A6A6A6")
# 
# cbPalette_sex_diff <- 
#   c("#D9D9D9", "#D9D9D9", "#D9D9D9", 
#     "#D9D9D9", "#A6A6A6")
# 
# # plot the comparative LTRE results
# vital_rate_theme <- 
#   theme_bw() +
#   theme(
#     text = element_text(family = "Verdana"),
#     legend.position = "none",
#     panel.grid.major = element_blank(),
#     panel.grid.minor = element_blank(),
#     axis.ticks.length = unit(0.1, "cm"),
#     panel.border = element_blank(),
#     panel.spacing.x = unit(0.3, "lines"),
#     panel.spacing.y = unit(0.7, "lines"),
#     strip.background = element_blank()
#   )
# species.labs <- c("Black Coucal", "White-browed Coucal")
# names(species.labs) <- c("BC", "WBC")

Project-specific Functions

The following custom functions are used to

%!in%

This function simply does the opposite of %in%, which is used to test if elements on the left-hand side are members of the set defined by the right-hand side. %!in% returns a logical vector indicating whether each element on the left-hand side is not present in the right-hand side.

Code
`%!in%` = Negate(`%in%`)

lucinda_nest_import()

This function imports the HOPL nest survival data stored as Excel sheets into R, wrangles it into a single dataframe, and prepares it for subsequent analysis (e.g., specifies relevent date columns, etc.)

arguments:

  • year_1: first calender year of the focal data sheet (e.g., 2002)
  • year_2: second calender year of the focal data set (i.e., always year_1 + 1)
  • file_name: name of the Excel sheet to import data from
  • site: site that the data describes (MP, FP, or BSC)
  • extra_text: the extra text associated with each sheet in the Excel file (i.e., besides from the year)
  • first_found_date_col: the number of the column in the sheets that correspond to the first found date
  • last_alive_date_col: the number of the column in the sheets that correspond to the last alive date
  • last_checked_col: the number of the column in the sheets that correspond to the last checked date
Code
lucinda_nest_import <-
  function(year_1, year_2, file_name, site, extra_text = NULL, 
           first_found_date_col, last_alive_date_col, last_checked_col) {
    if(is.null(extra_text)){
      file <- 
        read_excel(paste0("data/final/final_final/final_final_final/", file_name), 
                   sheet = paste0(site, " ", year_1, "_", str_sub(year_2, 3, 4)), 
                   col_types = "text", na = "n/a")
    }
    else{
    file <- 
      read_excel(paste0("data/final/final_final/final_final_final/", file_name), 
                 sheet = paste0(site, " ", year_1, "_", str_sub(year_2, 3, 4), extra_text), 
                 col_types = "text", na = "n/a")
    }
    file %>%
      # simplify column names
      rename(first_found = first_found_date_col,
             last_alive = last_alive_date_col,
             last_checked = last_checked_col,
             Fate = `Hatch?`,
             season = Season,
             site = Site,
             nest_ID = `Nest ID`,
             nest_hab = `Nest habitat`,
             management_status = `Nest managed?`,
             management_type = `Management type`,
             nest_lat = `Nest latitude`,
             nest_lon = `Nest longitude`) %>% 
      
      # consolidate columns
      dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                    management_status, management_type, nest_lat, nest_lon, site) %>% 
      
      # wrangle: clean up Fate column for consistency
      mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
      mutate(Fate = toupper(Fate)) %>% 
      
      # wrangle: if date last alive is "Unk." make it "NA"
      mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
             # change Fate to 1 or 0 (1 = failed, 0 = hatched, NA = unknown)
             Fate = ifelse(Fate == "Y", 0, 
                           ifelse(Fate == "N", 1, 
                                  ifelse(Fate == "UNK", NA, "XXX")))) %>%
    mutate(
        # wrangle: if last_alive has a date and last_checked is NA, then change 
        # last_checked to the date in last_alive
        last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                              last_alive,
                              # if both last_alive and last_checked is "NA", then
                              # change last_checked to the first_found date
                              ifelse(is.na(last_alive) & is.na(last_checked),
                                     first_found,
                                     last_checked))) %>%
      mutate(
        # wrangle: if last_alive is NA and the nest hatched and last_checked has a
        # date, then specify last_alive as the date from last_checked
        last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                            last_checked,
                            # if the last_alive is NA and the nest failed and 
                            # last_checked has a date, then specify last_alive as the
                            # date from first_found
                            ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                                   first_found,
                                   last_alive))) %>%
      filter(nchar(first_found) == 8 & nchar(last_alive) == 8 & nchar(last_checked) == 8) %>%
      # specify date columns as a date string
      mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                          str_sub(first_found, 3, 4),
                                          str_sub(first_found, 1, 2), sep = "-")),
             last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                         str_sub(last_alive, 3, 4),
                                         str_sub(last_alive, 1, 2), sep = "-")),
             last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                           str_sub(last_checked, 3, 4),
                                           str_sub(last_checked, 1, 2), sep = "-"))) %>%
      # if last checked date is before last alive date, then change it to the 
      # last alive date, if not then leave as is
      # mutate(last_checked2 = ifelse(last_checked2 < last_alive2 | (is.na(last_checked2) & !is.na(last_alive2)), last_alive2, last_checked2)) %>%
      # julian dates
      mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
             LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
             LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
      # remove all nests that have unknown fate
      filter(!is.na(Fate)) %>% 
      # clean up the management_type column
      mutate(management_type = tolower(management_type)) %>% 
      mutate(management_type = str_replace(management_type, "acess", "access")) %>% 
      mutate(management_type = str_replace(management_type, "and", ",")) %>% 
      mutate(management_type = str_replace(management_type, "temporary", "")) %>% 
      mutate(management_type = str_replace_all(management_type, " ", "")) %>% 
      mutate(management_type = str_replace_all(management_type, "shelters", "")) %>% 
      mutate(management_type = str_replace_all(management_type, "banners", "")) %>% 
      mutate(management_type = str_replace_all(management_type, ",,", ",")) %>% 
      mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>% 
      mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>% 
      mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>% 
      mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
      mutate(none = ifelse(str_detect(management_type, "none"), 1, 0)) %>% 
      mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>% 
      mutate(management_level = ifelse(sign_access == 1 & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                       ifelse(rope_fence == 1, 3,
                                              ifelse(sign_nest == 1, 2,
                                                     ifelse(sign_access == 1, 1, 
                                                            ifelse(none == 1, 0, NA)))))) %>% 
      mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>% 
      mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>% 
      mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>% 
      mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>% 
      mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>% 
      dplyr::select(#-management_type, -sign_access, -sign_nest, -rope_fence,
                    #-wardens, -none, 
                    -other,
                    -sign_nest_no_sign_access, -fence_no_sign,
                    -wardens_no_sign, -wardens_no_fence, -just_wardens) %>% 
      mutate(site = str_extract(nest_ID, "_([^_]+)_") %>% str_remove_all("_"))
    }

Importing and checking nest survival data

Mornington Peninsula

Flag potential issues in data

First we import the data and run a few checks to assess if there are any rows with the following issues:

  1. found date is not 8 characters

  2. last seen alive date is not 8 characters

  3. last checked date is not 8 characters

  4. found date missing

  5. last seen alive date missing

  6. last checked date missing

  7. Nest managed? is not Y or N

  8. Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks

  9. Management type is not sufficient for making levels

  10. Double check dates because incubation time greater than 35 days

  11. Found date is after Last Alive date (should be greater or equal)

  12. Found date is after Last Checked date (should be greater or equal)

  13. Last Checked date is before Last Alive date (should be greater or equal)

Code
suppressMessages(
  bind_rows(
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"), 
  read_excel(paste0("data/final/final_final/final_final_final/", "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("MP", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    filter(!is.na(Season)) %>% 
    rename(first_found = 10,
           last_alive = 27,
           last_checked = 32,
           Fate = `Hatch?`,
           season = Season,
           site = Site,
           nest_ID = `Nest ID`,
           nest_hab = `Nest habitat`,
           management_status = `Nest managed?`,
           management_type = `Management type`,
           nest_lat = `Nest latitude`,
           nest_lon = `Nest longitude`) %>% 
    dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                  management_status, management_type, nest_lat, nest_lon, site) %>% 
    mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
    mutate(Fate = toupper(Fate)) %>% 
    mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
           Fate = ifelse(Fate == "Y", 0, 
                          ifelse(Fate == "N", 1, 
                                 ifelse(Fate == "UNK", NA, "XXX")))) %>%
    mutate(
      last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                            last_alive,
                            ifelse(is.na(last_alive) & is.na(last_checked),
                                   first_found,
                                   last_checked))) %>%
    mutate(
      last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                          last_checked,
                          ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                                 first_found,
                                 last_alive))) %>% 
    mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                        str_sub(first_found, 3, 4),
                                        str_sub(first_found, 1, 2), sep = "-")),
           last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                       str_sub(last_alive, 3, 4),
                                       str_sub(last_alive, 1, 2), sep = "-")),
           last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                         str_sub(last_checked, 3, 4),
                                         str_sub(last_checked, 1, 2), sep = "-"))) %>%
    mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
           LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
           LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>%
    mutate(management_type = tolower(management_type)) %>%
    mutate(management_type = str_replace(management_type, "acess", "access")) %>%
    mutate(management_type = str_replace(management_type, "and", ",")) %>%
    mutate(management_type = str_replace(management_type, "temporary", "")) %>%
    mutate(management_type = str_replace_all(management_type, " ", "")) %>%
    mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
    mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
    mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
    mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
    mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
    mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
    mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>%
    mutate(none = ifelse(str_detect(management_type, "none"), 1, 0)) %>%
    mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
    mutate(management_level = ifelse(sign_access == 1 & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                     ifelse(rope_fence == 1, 3,
                                            ifelse(sign_nest == 1, 2,
                                                   ifelse(sign_access == 1, 1,
                                                          ifelse(none == 1, 0, NA)))))) %>%
    mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
    mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
    mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
    mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
    mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
    dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                  -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
    group_by(season) %>%
    mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
           season = as.factor(season),
           nest_hab = as.factor(nest_hab),
           management_status = as.factor(management_status)) %>% 
    mutate(region = "MP") %>%
    mutate(site = as.factor(site)) %>%
    mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
    mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
    mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
    mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
    mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
    mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
    mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
    mutate(issue8 = ifelse(nest_hab %!in% c("Beach", "Dune", "Foredune/face", "Estuary/spit", "Rocks"), "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ", NA)) %>% 
    mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
    mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
    mutate(issue10 = ifelse(found_and_alive_diff > 35 , "Double check dates because incubation time greater than 35 days; ", NA)) %>% 
    mutate(issue11 = ifelse(FirstFound > LastPresent, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
    mutate(issue12 = ifelse(FirstFound > LastChecked, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
    mutate(issue13 = ifelse(LastChecked < LastPresent, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
    mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                             is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                             is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                             is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                           paste0(issue1, issue2, issue3, 
                                  issue4, issue5, issue6, 
                                  issue7, issue8, issue9,
                                  issue10, issue11, issue12, issue13))) %>% 
    mutate(issues = str_remove_all(issues, "NA")) %>% 
    mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
    dplyr::select(-issue1, -issue2, -issue3, 
                  -issue4, -issue5, -issue6, 
                  -issue7, -issue8, -issue9, 
                  -issue10, -issue11, -issue12, -issue13) %>% 
    filter(issues != "usable") %>% 
    arrange(issues) %>%
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>% 
  filter(str_detect(issues, "date")) %>% 
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>% 
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>% 
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, Fate, found_and_alive_diff, issues) %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
  # write_csv(., "data/final/final_final/final_final_final/nest_issues_commented/MP Nesting Summary 2020_21 to 2006_07 site names match threat data_nests_w_issues_commented.csv", col_names = TRUE, append = FALSE, quote = "all")

Import data

Code
nest_data_MP <-
  bind_rows(
    lucinda_nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2011", year_2 = "2012", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2010", year_2 = "2011", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2009", year_2 = "2010", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2008", year_2 = "2009", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2007", year_2 = "2008", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32),
    lucinda_nest_import(year_1 = "2006", year_2 = "2007", 
                        file_name = "MP Nesting Summary 2020_21 to 2006_07 fix ups post email from Luke 27_2_24.xlsx", site = "MP",
                        first_found_date_col = 10, 
                        last_alive_date_col = 27, 
                        last_checked_col = 32)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("Beach", "Dune", "Foredune/face", "Estuary/spit", "Rocks")) %>%
  filter(!is.na(management_level)) %>% 
  mutate(region = "MP") %>% 
  mutate(site = as.factor(site)) %>% 
  ungroup()

Visual inspections of data

Code
nest_data_MP_check <-
  nest_data_MP %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)),
         Fate = as.factor(Fate))
Spatial distribution of data

Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata

Code
nest_data_MP %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>%
  mapview(popup = popupTable(.,
                             zcol = c("season",
                                      "site",
                                      "nest_ID")))
Year-specific Found Date Distributions
Code
ggplot(nest_data_MP_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Alive Date Distributions
Code
ggplot(nest_data_MP_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Checked Date Distributions
Code
  ggplot(nest_data_MP_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Incubation length distribution
Code
# assess if there are nests with unusually long incubation periods
nest_data_MP_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")

# A tibble: 0 × 26
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …
# A tibble: 0 × 26
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …
# A tibble: 1 × 26
  season site        nest_ID  first_found last_alive last_checked Fate  nest_hab
  <fct>  <fct>       <chr>    <chr>       <chr>      <chr>        <chr> <fct>   
1 201516 Koonya East 201516_… 17012016    15022016   16012016     0     Foredun…
# ℹ 18 more variables: management_status <fct>, management_type <chr>,
#   nest_lat <chr>, nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, region <chr>

Fleurieu Peninsula

Flag potential issues in data

As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above

Code
suppressMessages(bind_rows(
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2020", "_", str_sub("2021", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2019", "_", str_sub("2020", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2018", "_", str_sub("2019", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2017", "_", str_sub("2018", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2016", "_", str_sub("2017", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2015", "_", str_sub("2016", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2014", "_", str_sub("2015", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2013", "_", str_sub("2014", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2012", "_", str_sub("2013", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2011", "_", str_sub("2012", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2010", "_", str_sub("2011", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx"), 
             sheet = paste0("FP", " ", "2009", "_", str_sub("2010", 3, 4), " Nest summary"), 
             col_types = "text", na = "n/a"))) %>% 
    rename(first_found = 10,
           last_alive = 29,
           last_checked = 36,
           Fate = `Hatch?`,
           season = Season,
           site = Site,
           nest_ID = `Nest ID`,
           nest_hab = `Nest habitat`,
           management_status = `Nest managed?`,
           management_type = `Management type`,
           nest_lat = `Nest latitude`,
           nest_lon = `Nest longitude`) %>% 
    dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                  management_status, management_type, nest_lat, nest_lon, site) %>% 
    mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
    mutate(Fate = toupper(Fate)) %>% 
    mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
           Fate = ifelse(Fate == "Y", 0, 
                          ifelse(Fate == "N", 1, 
                                 ifelse(Fate == "UNK", NA, "XXX")))) %>%
    mutate(
      last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                            last_alive,
                            ifelse(is.na(last_alive) & is.na(last_checked),
                                   first_found,
                                   last_checked))) %>%
    mutate(
      last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                          last_checked,
                          ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                                 first_found,
                                 last_alive))) %>% 
    mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                        str_sub(first_found, 3, 4),
                                        str_sub(first_found, 1, 2), sep = "-")),
           last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                       str_sub(last_alive, 3, 4),
                                       str_sub(last_alive, 1, 2), sep = "-")),
           last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                         str_sub(last_checked, 3, 4),
                                         str_sub(last_checked, 1, 2), sep = "-"))) %>%
    mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
           LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
           LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>%
    mutate(management_type = tolower(management_type)) %>%
    mutate(management_type = str_replace(management_type, "acess", "access")) %>%
    mutate(management_type = str_replace(management_type, "and", ",")) %>%
    mutate(management_type = str_replace(management_type, "temporary", "")) %>%
    mutate(management_type = str_replace_all(management_type, " ", "")) %>%
    mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
    mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
    mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
    mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
    mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
    mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
    mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>%
    mutate(none = ifelse(str_detect(management_type, "none"), 1, 0)) %>%
    mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
    mutate(management_level = ifelse(sign_access == 1 & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                     ifelse(rope_fence == 1, 3,
                                            ifelse(sign_nest == 1, 2,
                                                   ifelse(sign_access == 1, 1,
                                                          ifelse(none == 1, 0, NA)))))) %>%
    mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
    mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
    mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
    mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
    mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
    dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                  -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
    group_by(season) %>%
    mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
           season = as.factor(season),
           nest_hab = as.factor(nest_hab),
           management_status = as.factor(management_status)) %>% 
    mutate(region = "FP") %>%
    mutate(site = as.factor(site)) %>%
    mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
    mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
    mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
    mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
    mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
    mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
    mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
    mutate(issue8 = ifelse(nest_hab %!in% c("Beach", "Dune", "Foredune/face", "Estuary/spit", "Rocks"), "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ", NA)) %>% 
    mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
    mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
    mutate(issue10 = ifelse(found_and_alive_diff > 35 , "Double check dates because incubation time greater than 35 days; ", NA)) %>% 
    mutate(issue11 = ifelse(FirstFound > LastPresent, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
    mutate(issue12 = ifelse(FirstFound > LastChecked, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
    mutate(issue13 = ifelse(LastChecked < LastPresent, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
    mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                             is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                             is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                             is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                           paste0(issue1, issue2, issue3, 
                                  issue4, issue5, issue6, 
                                  issue7, issue8, issue9,
                                  issue10, issue11, issue12, issue13))) %>% 
    mutate(issues = str_remove_all(issues, "NA")) %>% 
    mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
    dplyr::select(-issue1, -issue2, -issue3, 
                  -issue4, -issue5, -issue6, 
                  -issue7, -issue8, -issue9, 
                  -issue10, -issue11, -issue12, -issue13) %>% 
    filter(issues != "usable") %>% 
    arrange(issues) %>%
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited" & last_checked != "Not revisted") %>% 
  filter(str_detect(issues, "date")) %>% 
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>% 
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, Fate, found_and_alive_diff, issues) %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')#%>%
Code
  # write_csv(., "data/final/final_final/final_final_final/nest_issues_commented/FP Nesting summary 2020_21 to 2009_10 FINAL- checking names consistent for threat data_nests_w_issues_commented.csv", col_names = TRUE, append = FALSE, quote = "all")

Import data

Code
nest_data_FP <-
  bind_rows(
    lucinda_nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2017", year_2 = "2018",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2016", year_2 = "2017",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2015", year_2 = "2016",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2014", year_2 = "2015",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2013", year_2 = "2014",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2012", year_2 = "2013",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2011", year_2 = "2012",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2010", year_2 = "2011",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36),
    lucinda_nest_import(year_1 = "2009", year_2 = "2010",
                        file_name = "FP Nesting summary 2020_21 to 2009_10 FINAL- no changes made post email from luke 27_2_24.xlsx", site = "FP", extra_text = " Nest summary",
                        first_found_date_col = 10, 
                        last_alive_date_col = 29, 
                        last_checked_col = 36)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("Beach", "Dune", "Foredune/face")) %>%
  filter(!is.na(management_level)) %>% 
  mutate(region = "FP") %>% 
  mutate(site = as.factor(site))

Visual inspections of data

Code
nest_data_FP_check <-
  nest_data_FP %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))
Spatial distribution of data

Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata

Code
nest_data_FP %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>%
  mapview(popup = popupTable(.,
                             zcol = c("season",
                                      "site",
                                      "nest_ID")))
Year-specific Found Date Distributions
Code
ggplot(nest_data_FP_check, aes(first_found2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 10), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Alive Date Distributions
Code
ggplot(nest_data_FP_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 10), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Checked Date Distributions
Code
ggplot(nest_data_FP_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 10), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Incubation length distribution
Code
# assess if there are nests with unusually long incubation periods
nest_data_FP_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  filter(FirstFound < LastPresent & FirstFound < LastChecked) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")

# A tibble: 0 × 26
# Groups:   season [0]
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …
# A tibble: 0 × 26
# Groups:   season [0]
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …
# A tibble: 0 × 26
# Groups:   season [0]
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …

Bellarine / Surf Coast

Flag potential issues in data

As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above

Code
suppressMessages(bind_rows(
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/final/final_final/final_final_final/", "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx"), 
             sheet = paste0("BellSurfCoast", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    rename(first_found = 10,
           last_alive = 29,
           last_checked = 36,
           Fate = `Hatch?`,
           season = Season,
           site = Site,
           nest_ID = `Nest ID`,
           nest_hab = `Nest habitat`,
           management_status = `Nest managed?`,
           management_type = `Management type`,
           nest_lat = `Nest latitude`,
           nest_lon = `Nest longitude`) %>% 
    dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                  management_status, management_type, nest_lat, nest_lon, site) %>% 
    mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
    mutate(Fate = toupper(Fate)) %>% 
    mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
           Fate = ifelse(Fate == "Y", 0, 
                          ifelse(Fate == "N", 1, 
                                 ifelse(Fate == "UNK", NA, "XXX")))) %>%
    mutate(
      last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                            last_alive,
                            ifelse(is.na(last_alive) & is.na(last_checked),
                                   first_found,
                                   last_checked))) %>%
    mutate(
      last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                          last_checked,
                          ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                                 first_found,
                                 last_alive))) %>% 
    mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                        str_sub(first_found, 3, 4),
                                        str_sub(first_found, 1, 2), sep = "-")),
           last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                       str_sub(last_alive, 3, 4),
                                       str_sub(last_alive, 1, 2), sep = "-")),
           last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                         str_sub(last_checked, 3, 4),
                                         str_sub(last_checked, 1, 2), sep = "-"))) %>%
    mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
           LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
           LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>%
    mutate(management_type = tolower(management_type)) %>%
    mutate(management_type = str_replace(management_type, "acess", "access")) %>%
    mutate(management_type = str_replace(management_type, "and", ",")) %>%
    mutate(management_type = str_replace(management_type, "temporary", "")) %>%
    mutate(management_type = str_replace_all(management_type, " ", "")) %>%
    mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
    mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
    mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
    mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
    mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
    mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
    mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>%
    mutate(none = ifelse(str_detect(management_type, "none"), 1, 0)) %>%
    mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
    mutate(management_level = ifelse(sign_access == 1 & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                     ifelse(rope_fence == 1, 3,
                                            ifelse(sign_nest == 1, 2,
                                                   ifelse(sign_access == 1, 1,
                                                          ifelse(none == 1, 0, NA)))))) %>%
    mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
    mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
    mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
    mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
    mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
    dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                  -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
    group_by(season) %>%
    mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
           season = as.factor(season),
           nest_hab = as.factor(nest_hab),
           management_status = as.factor(management_status)) %>% 
    mutate(region = "BellSurfCoast") %>%
    mutate(site = as.factor(site)) %>%
    mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
    mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
    mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
    mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
    mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
    mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
    mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
    mutate(issue8 = ifelse(nest_hab %!in% c("Beach", "Dune", "Foredune/face", "Estuary/spit", "Rocks"), "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ", NA)) %>% 
    mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
    mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
    mutate(issue10 = ifelse(found_and_alive_diff > 35 , "Double check dates because incubation time greater than 35 days; ", NA)) %>% 
    mutate(issue11 = ifelse(FirstFound > LastPresent, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
    mutate(issue12 = ifelse(FirstFound > LastChecked, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
    mutate(issue13 = ifelse(LastChecked < LastPresent, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
    mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                             is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                             is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                             is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                           paste0(issue1, issue2, issue3, 
                                  issue4, issue5, issue6, 
                                  issue7, issue8, issue9,
                                  issue10, issue11, issue12, issue13))) %>% 
    mutate(issues = str_remove_all(issues, "NA")) %>% 
    mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
    dplyr::select(-issue1, -issue2, -issue3, 
                  -issue4, -issue5, -issue6, 
                  -issue7, -issue8, -issue9, 
                  -issue10, -issue11, -issue12, -issue13) %>% 
    filter(issues != "usable") %>% 
    arrange(issues) %>%
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited" & last_checked != "Not revisted") %>% 
  filter(str_detect(issues, "date")) %>% 
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>% 
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>% 
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, Fate, found_and_alive_diff, issues) %>% 
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')#%>%
Code
  # write_csv(., "data/final/final_final/final_final_final/nest_issues_commented/Bellarine_Surf Coast Nesting with site names matching with threat data doc_nests_w_issues_commented.csv", col_names = TRUE, append = FALSE, quote = "all")

Import data

Code
nest_data_BSC <-
  bind_rows(
    lucinda_nest_import(year_1 = "2020", year_2 = "2021", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2019", year_2 = "2020", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2018", year_2 = "2019", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2017", year_2 = "2018", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2016", year_2 = "2017", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2015", year_2 = "2016", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2014", year_2 = "2015", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2013", year_2 = "2014", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2012", year_2 = "2013", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2011", year_2 = "2012", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2010", year_2 = "2011", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2009", year_2 = "2010", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2008", year_2 = "2009", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2007", year_2 = "2008", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
    lucinda_nest_import(year_1 = "2006", year_2 = "2007", 
                        first_found_date_col = 10, last_alive_date_col = 29, last_checked_col = 36,
                        file_name = "Bellarine_Surf Coast Nesting 2006_2021 fix ups post email from Luke 27_2_24.xlsx", site = "BellSurfCoast"),
  ) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>%
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>%
  filter(management_status %in% c("Y", "N")) %>%
  filter(nest_hab %in% c("Beach", "Dune", "Foredune/face")) %>%
  filter(!is.na(management_level)) %>%
  mutate(region = "BSC") %>%
  mutate(site = as.factor(site))

Visual inspections of data

Code
nest_data_BSC_check <-
  nest_data_BSC %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))
Spatial distribution of data

Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata

Code
nest_data_BSC %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>%
  mapview(popup = popupTable(.,
                             zcol = c("season",
                                      "site",
                                      "nest_ID")))
Year-specific Found Date Distributions
Code
ggplot(nest_data_BSC_check, aes(first_found2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  # scale_y_continuous(limits = c(0, 10), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Alive Date Distributions
Code
ggplot(nest_data_BSC_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  # scale_y_continuous(limits = c(0, 10), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Checked Date Distributions
Code
ggplot(nest_data_BSC_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  # scale_y_continuous(limits = c(0, 10), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Incubation length distribution
Code
# assess if there are nests with unusually long incubation periods
nest_data_BSC_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  filter(FirstFound < LastPresent & FirstFound < LastChecked) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")

# A tibble: 0 × 26
# Groups:   season [0]
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …
# A tibble: 0 × 26
# Groups:   season [0]
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …
# A tibble: 0 × 26
# Groups:   season [0]
# ℹ 26 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, first_found2 <date>, last_alive2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   wardens <dbl>, none <dbl>, management_level <dbl>, nocc <dbl>, …

Importing and checking threat data

Code
FP_threat_data <- 
  read_excel("data/final/final_final/Merged threat data_FP_MP.xlsx",
             sheet = "FP Threat DATA", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  filter(Region %in% c("Fleurieu Peninsula")) %>% 
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation Date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "FP")

MP_threat_data <- 
  read_excel("data/final/final_final/Merged threat data_FP_MP.xlsx",
             sheet = "MP Threat DATA", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  filter(Region %in% c("Mornington Peninsula")) %>% 
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation Date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "MP")

BSC_threat_data <- 
  read_excel("data/final/final_final/Merged threat data_BSC.xlsx",
             sheet = "BellSurf Threat DATA", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "BSC")

threat_data <- 
  bind_rows(FP_threat_data, MP_threat_data, BSC_threat_data)
Code
threat_data_ <-
  threat_data %>% 
  rename(site = `Site name`) %>% 
  # first convert all the count columns to numeric
  mutate_at(vars(
    `Walkers/Joggers (wet sand)`,`Walkers/Joggers (dry sand)`,
    `Walkers/Joggers (signs/fence)`,`Walkers/Joggers (Dune)`,`People sunbaking/sitting (wet sand)`,
    `People sunbaking/sitting (dry sand)`,`People sunbaking/sitting (signs/fence)`,
    `People sunbaking/sitting (Dune)`,`Surfers/Swimmers (wet sand)`,
    `Surfers/Swimmers (dry sand)`,`Surfers/Swimmers (signs/fence)`,
    `Surfers/Swimmers (Dune)`,`People Fishing (wet sand)`,
    `People Fishing (dry sand)`,`People Fishing (signs/fence)`,
    `People Fishing (Dune)`,`People Playing Games (wet sand)`,
    `People Playing Games (dry sand)`,`People Playing Games (signs/fence)`,
    `People Playing Games (Dune)`,`Dog Walkers (wet sand)`,
    `Dog Walkers (dry sand)`,`Dog Walkers (signs/fence)`,
    `Dog Walkers (Dune)`,`Dog On Leash (# dogs) (wet sand)`,
    `Dog On Leash (# dogs) (dry sand)`,`Dog On Leash (# dogs) (signs/fence)`,
    `Dog On Leash (# dogs) (Dune)`,`Dog Off Leash (# dogs) (wet sand)`,
    `Dog Off Leash (# dogs) (dry sand)`,`Dog Off Leash (# dogs) (signs/fence)`,
    `Dog Off Leash (# dogs) (Dune)`,`Horses (wet sand)`,
    `Horses (dry sand)`,`Horses (signs/fence)`,
    `Horses (Dune)`,`Permitted vehicle (wet sand)`,
    `Permitted vehicle (dry sand)`,`Permitted vehicle (signs/fence)`,
    `Permitted vehicle (Dune)`,`Illegal vehicle (wet sand)`,
    `Illegal vehicle (dry sand)`,`Illegal vehicle (signs/fence)`,
    `Illegal vehicle (Dune)`,`Ravens (wet sand)`,                     
    `Ravens (dry sand)`,`Ravens (signs/fence)`, 
    `Ravens (Dune)`,`Magpies (wet sand)`, 
    `Magpies (dry sand)`,`Magpies (signs/fence)`, 
    `Magpies (Dune)`,`Silver Gulls (wet sand)`,  
    `Silver Gulls (dry sand)`,`Silver Gulls (signs/fence)`,
    `Silver Gulls (Dune)`,`Pacific/Kelp Gulls (wet sand)`,
    `Pacific/Kelp Gulls (dry sand)`,`Pacific/Kelp Gulls (signs/fence)`,
    `Pacific/Kelp Gulls (Dune)`,`Nankeen Kestrels (wet sand)`,
    `Nankeen Kestrels (dry sand)`,`Nankeen Kestrels (signs/fence)`,
    `Nankeen Kestrels (Dune)`,`Other bird of prey (wet sand)`,
    `Other bird of prey (dry sand)`,`Other bird of prey (signs/fence)`,
    `Other bird of prey (Dune)`,
    `Stock (cattle/sheep) (wet sand)`,
    `Stock (cattle/sheep) (dry sand)`,`Stock (cattle/sheep) (signs/fence)`,
    `Stock (cattle/sheep) (Dune)`), as.numeric) %>% 
  ungroup() %>% 
  
  # take the total sum of counts for each threat type (e.g., humans includes
  # Dog Walkers, People Playing Games, People Fishing, Surfers/Swimmers, 
  # People sunbaking/sitting, and Walkers/Joggers)
  mutate(humans = rowSums(dplyr::select(.,`Walkers/Joggers (wet sand)`, 
                                        `Walkers/Joggers (dry sand)`, 
                                        `Walkers/Joggers (signs/fence)`, 
                                        `Walkers/Joggers (Dune)`, 
                                        `People sunbaking/sitting (wet sand)`, 
                                        `People sunbaking/sitting (dry sand)`, 
                                        `People sunbaking/sitting (signs/fence)`, 
                                        `People sunbaking/sitting (Dune)`, 
                                        `Surfers/Swimmers (wet sand)`, 
                                        `Surfers/Swimmers (dry sand)`, 
                                        `Surfers/Swimmers (signs/fence)`, 
                                        `Surfers/Swimmers (Dune)`, 
                                        `People Fishing (wet sand)`, 
                                        `People Fishing (dry sand)`, 
                                        `People Fishing (signs/fence)`, 
                                        `People Fishing (Dune)`, 
                                        `People Playing Games (wet sand)`, 
                                        `People Playing Games (dry sand)`, 
                                        `People Playing Games (signs/fence)`, 
                                        `People Playing Games (Dune)`, 
                                        `Dog Walkers (wet sand)`, 
                                        `Dog Walkers (dry sand)`, 
                                        `Dog Walkers (signs/fence)`, 
                                        `Dog Walkers (Dune)`), na.rm = TRUE),
         # do a micro-habitat specific sum for humans
         humans_wet = rowSums(dplyr::select(.,`Walkers/Joggers (wet sand)`, 
                                            `People sunbaking/sitting (wet sand)`, 
                                            `Surfers/Swimmers (wet sand)`, 
                                            `People Fishing (wet sand)`, 
                                            `People Playing Games (wet sand)`, 
                                            `Dog Walkers (wet sand)`), na.rm = TRUE),
         humans_dry = rowSums(dplyr::select(.,`Walkers/Joggers (dry sand)`, 
                                            `People sunbaking/sitting (dry sand)`, 
                                            `Surfers/Swimmers (dry sand)`, 
                                            `People Fishing (dry sand)`, 
                                            `People Playing Games (dry sand)`, 
                                            `Dog Walkers (dry sand)`), na.rm = TRUE),
         humans_dune = rowSums(dplyr::select(.,`Walkers/Joggers (Dune)`, 
                                             `People sunbaking/sitting (Dune)`, 
                                            `Surfers/Swimmers (Dune)`, 
                                            `People Fishing (Dune)`, 
                                            `People Playing Games (Dune)`, 
                                            `Dog Walkers (Dune)`), na.rm = TRUE),
         humans_SF = rowSums(dplyr::select(.,`Walkers/Joggers (signs/fence)`, 
                                            `People sunbaking/sitting (signs/fence)`, 
                                            `Surfers/Swimmers (signs/fence)`, 
                                            `People Fishing (signs/fence)`, 
                                            `People Playing Games (signs/fence)`, 
                                            `Dog Walkers (signs/fence)`), na.rm = TRUE),
       dogs = rowSums(dplyr::select(., `Dog On Leash (# dogs) (wet sand)`, 
                                    `Dog On Leash (# dogs) (dry sand)`,
                                    `Dog On Leash (# dogs) (signs/fence)`, 
                                    `Dog On Leash (# dogs) (Dune)`, 
                                    `Dog Off Leash (# dogs) (wet sand)`, 
                                    `Dog Off Leash (# dogs) (dry sand)`, 
                                    `Dog Off Leash (# dogs) (signs/fence)`, 
                                    `Dog Off Leash (# dogs) (Dune)`), na.rm = TRUE),
       # specify a dog on leash and a dog of leash summary
       dogs_on = rowSums(dplyr::select(., `Dog On Leash (# dogs) (wet sand)`, 
                                       `Dog On Leash (# dogs) (dry sand)`,
                                       `Dog On Leash (# dogs) (signs/fence)`, 
                                       `Dog On Leash (# dogs) (Dune)`), na.rm = TRUE),
       dogs_off = rowSums(dplyr::select(., `Dog Off Leash (# dogs) (wet sand)`, 
                                        `Dog Off Leash (# dogs) (dry sand)`, 
                                        `Dog Off Leash (# dogs) (signs/fence)`, 
                                        `Dog Off Leash (# dogs) (Dune)`), na.rm = TRUE),
       pred_birds = rowSums(dplyr::select(., `Ravens (wet sand)`, 
                                          `Ravens (dry sand)`, 
                                          `Ravens (signs/fence)`, 
                                          `Ravens (Dune)`, 
                                          `Magpies (wet sand)`, 
                                          `Magpies (dry sand)`, 
                                          `Magpies (signs/fence)`, 
                                          `Magpies (Dune)`#, 
                                          # `Silver Gulls (wet sand)`,
                                          # `Silver Gulls (dry sand)`,
                                          # `Silver Gulls (signs/fence)`,
                                          # `Silver Gulls (Dune)`,
                                          # `Pacific/Kelp Gulls (wet sand)`,
                                          # `Pacific/Kelp Gulls (dry sand)`,
                                          # `Pacific/Kelp Gulls (signs/fence)`,
                                          # `Pacific/Kelp Gulls (Dune)`,
                                          # `Nankeen Kestrels (wet sand)`, 
                                          # `Nankeen Kestrels (dry sand)`, 
                                          # `Nankeen Kestrels (signs/fence)`, 
                                          # `Nankeen Kestrels (Dune)`, 
                                          # `Other bird of prey (wet sand)`, 
                                          # `Other bird of prey (dry sand)`, 
                                          # `Other bird of prey (signs/fence)`, 
                                          # `Other bird of prey (Dune)`
                                          ), na.rm = TRUE),
       gulls = rowSums(dplyr::select(., #`Ravens (wet sand)`, 
                                          # `Ravens (dry sand)`, 
                                          # `Ravens (signs/fence)`, 
                                          # `Ravens (Dune)`, 
                                          # `Magpies (wet sand)`, 
                                          # `Magpies (dry sand)`, 
                                          # `Magpies (signs/fence)`, 
                                          # `Magpies (Dune)` 
                                          `Silver Gulls (wet sand)`,
                                          `Silver Gulls (dry sand)`,
                                          `Silver Gulls (signs/fence)`,
                                          `Silver Gulls (Dune)`,
                                          `Pacific/Kelp Gulls (wet sand)`,
                                          `Pacific/Kelp Gulls (dry sand)`,
                                          `Pacific/Kelp Gulls (signs/fence)`,
                                          `Pacific/Kelp Gulls (Dune)`
                                          # `Nankeen Kestrels (wet sand)`, 
                                          # `Nankeen Kestrels (dry sand)`, 
                                          # `Nankeen Kestrels (signs/fence)`, 
                                          # `Nankeen Kestrels (Dune)`, 
                                          # `Other bird of prey (wet sand)`, 
                                          # `Other bird of prey (dry sand)`, 
                                          # `Other bird of prey (signs/fence)`, 
                                          # `Other bird of prey (Dune)`
                                          ), na.rm = TRUE),
       vehicles = rowSums(dplyr::select(., `Permitted vehicle (wet sand)`, 
                                        `Permitted vehicle (dry sand)`, 
                                        `Permitted vehicle (signs/fence)`, 
                                        `Permitted vehicle (Dune)`, 
                                        `Illegal vehicle (wet sand)`, 
                                        `Illegal vehicle (dry sand)`, 
                                        `Illegal vehicle (signs/fence)`, 
                                        `Illegal vehicle (Dune)`), na.rm = TRUE),
       hoofed_animals = rowSums(dplyr::select(.,`Horses (wet sand)`, 
                                              `Horses (dry sand)`, 
                                              `Horses (signs/fence)`,
                                              `Horses (Dune)`, 
                                              `Stock (cattle/sheep) (wet sand)`, 
                                              `Stock (cattle/sheep) (dry sand)`, 
                                              `Stock (cattle/sheep) (signs/fence)`, 
                                              `Stock (cattle/sheep) (Dune)`), na.rm = TRUE)) %>% 
  # consolidate columns names
  rename(hum_pri_wet = `Human Prints (wet sand)`,
         hum_pri_dry = `Human Prints (dry sand)`,
         hum_pri_dune = `Human Prints (Dune)`,
         hum_pri_SF = `Human Prints (signs/fence)`,
         fox_pri_wet = `Fox Prints (wet sand)`,
         fox_pri_dry = `Fox Prints (dry sand)`,
         fox_pri_dune = `Fox Prints (Dune)`,
         fox_pri_SF = `Fox Prints (signs/fence)`,
         dog_pri_wet = `Dog Prints (wet sand)`,
         dog_pri_dry = `Dog Prints (dry sand)`,
         dog_pri_dune = `Dog Prints (Dune)`,
         dog_pri_SF = `Dog Prints (signs/fence)`,
         vehicle_pri_wet = `Vehicle Tracks (wet sand)`,
         vehicle_pri_dry = `Vehicle Tracks (dry sand)`,
         vehicle_pri_dune = `Vehicle Tracks (Dune)`,
         vehicle_pri_SF = `Vehicle Tracks (signs/fence)`,
         trailbike_pri_wet = `Trail bike tracks (wet sand)`,
         trailbike_pri_dry = `Trail bike tracks (dry sand)`,
         trailbike_pri_dune = `Trail bike tracks (Dune)`,
         trailbike_pri_SF = `Trail bike tracks (signs/fence)`,
         stock_pri_wet = `Stock (wet sand)`,
         stock_pri_dry = `Stock (dry sand)`,
         stock_pri_dune = `Stock (Dune)`,
         stock_pri_SF = `Stock (signs/fence)`,
         horse_pri_wet = `Horses Prints (wet sand)`,
         horse_pri_dry = `Horses Prints (dry sand)`,
         horse_pri_dune = `Horses Prints (Dune)`,
         horse_pri_SF = `Horses Prints (signs/fence)`) %>%
  # specify coordinates as numeric
  mutate(obs_lon = as.numeric(obs_lon),
         obs_lat = as.numeric(obs_lat)) %>% 
  # clean up factor levels (e.g., sometime "Light", sometimes just "L")
  mutate(hum_pri_wet = ifelse(hum_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_wet, 1, 1), 
                              ifelse(hum_pri_wet == "0", "N",
                                     ifelse(hum_pri_wet == "1", "L",
                                           ifelse(hum_pri_wet == "2", "M",
                                                  ifelse(hum_pri_wet == "3", "H",
                                                         ifelse(hum_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_dry = ifelse(hum_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_dry, 1, 1), 
                              ifelse(hum_pri_dry == "0", "N",
                                     ifelse(hum_pri_dry == "1", "L",
                                           ifelse(hum_pri_dry == "2", "M",
                                                  ifelse(hum_pri_dry == "3", "H",
                                                         ifelse(hum_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_SF =  ifelse(hum_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_SF, 1, 1), 
                              ifelse(hum_pri_SF == "0", "N",
                                     ifelse(hum_pri_SF == "1", "L",
                                           ifelse(hum_pri_SF == "2", "M",
                                                  ifelse(hum_pri_SF == "3", "H",
                                                         ifelse(hum_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_dune = ifelse(hum_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(hum_pri_dune, 1, 1), 
                              ifelse(hum_pri_dune == "0", "N",
                                     ifelse(hum_pri_dune == "1", "L",
                                           ifelse(hum_pri_dune == "2", "M",
                                                  ifelse(hum_pri_dune == "3", "H",
                                                         ifelse(hum_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_wet = ifelse(fox_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(fox_pri_wet, 1, 1), 
                              ifelse(fox_pri_wet == "0", "N",
                                     ifelse(fox_pri_wet == "1", "L",
                                           ifelse(fox_pri_wet == "2", "M",
                                                  ifelse(fox_pri_wet == "3", "H",
                                                         ifelse(fox_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_dry = ifelse(fox_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(fox_pri_dry, 1, 1), 
                              ifelse(fox_pri_dry == "0", "N",
                                     ifelse(fox_pri_dry == "1", "L",
                                           ifelse(fox_pri_dry == "2", "M",
                                                  ifelse(fox_pri_dry == "3", "H",
                                                         ifelse(fox_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_SF = ifelse(fox_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                             substr(fox_pri_SF, 1, 1), 
                              ifelse(fox_pri_SF == "0", "N",
                                     ifelse(fox_pri_SF == "1", "L",
                                           ifelse(fox_pri_SF == "2", "M",
                                                  ifelse(fox_pri_SF == "3", "H",
                                                         ifelse(fox_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_dune = ifelse(fox_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(fox_pri_dune, 1, 1), 
                              ifelse(fox_pri_dune == "0", "N",
                                     ifelse(fox_pri_dune == "1", "L",
                                           ifelse(fox_pri_dune == "2", "M",
                                                  ifelse(fox_pri_dune == "3", "H",
                                                         ifelse(fox_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_wet = ifelse(dog_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(dog_pri_wet, 1, 1), 
                              ifelse(dog_pri_wet == "0", "N",
                                     ifelse(dog_pri_wet == "1", "L",
                                           ifelse(dog_pri_wet == "2", "M",
                                                  ifelse(dog_pri_wet == "3", "H",
                                                         ifelse(dog_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_dry = ifelse(dog_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(dog_pri_dry, 1, 1), 
                              ifelse(dog_pri_dry == "0", "N",
                                     ifelse(dog_pri_dry == "1", "L",
                                           ifelse(dog_pri_dry == "2", "M",
                                                  ifelse(dog_pri_dry == "3", "H",
                                                         ifelse(dog_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_SF = ifelse(dog_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                             substr(dog_pri_SF, 1, 1), 
                              ifelse(dog_pri_SF == "0", "N",
                                     ifelse(dog_pri_SF == "1", "L",
                                           ifelse(dog_pri_SF == "2", "M",
                                                  ifelse(dog_pri_SF == "3", "H",
                                                         ifelse(dog_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_dune = ifelse(dog_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(dog_pri_dune, 1, 1), 
                              ifelse(dog_pri_dune == "0", "N",
                                     ifelse(dog_pri_dune == "1", "L",
                                           ifelse(dog_pri_dune == "2", "M",
                                                  ifelse(dog_pri_dune == "3", "H",
                                                         ifelse(dog_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_wet = ifelse(vehicle_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                  substr(vehicle_pri_wet, 1, 1), 
                              ifelse(vehicle_pri_wet == "0", "N",
                                     ifelse(vehicle_pri_wet == "1", "L",
                                           ifelse(vehicle_pri_wet == "2", "M",
                                                  ifelse(vehicle_pri_wet == "3", "H",
                                                         ifelse(vehicle_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_dry = ifelse(vehicle_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                  substr(vehicle_pri_dry, 1, 1), 
                              ifelse(vehicle_pri_dry == "0", "N",
                                     ifelse(vehicle_pri_dry == "1", "L",
                                           ifelse(vehicle_pri_dry == "2", "M",
                                                  ifelse(vehicle_pri_dry == "3", "H",
                                                         ifelse(vehicle_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_SF = ifelse(vehicle_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(vehicle_pri_SF, 1, 1), 
                              ifelse(vehicle_pri_SF == "0", "N",
                                     ifelse(vehicle_pri_SF == "1", "L",
                                           ifelse(vehicle_pri_SF == "2", "M",
                                                  ifelse(vehicle_pri_SF == "3", "H",
                                                         ifelse(vehicle_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_dune = ifelse(vehicle_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                   substr(vehicle_pri_dune, 1, 1), 
                              ifelse(vehicle_pri_dune == "0", "N",
                                     ifelse(vehicle_pri_dune == "1", "L",
                                           ifelse(vehicle_pri_dune == "2", "M",
                                                  ifelse(vehicle_pri_dune == "3", "H",
                                                         ifelse(vehicle_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_wet = ifelse(trailbike_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                    substr(trailbike_pri_wet, 1, 1), 
                              ifelse(trailbike_pri_wet == "0", "N",
                                     ifelse(trailbike_pri_wet == "1", "L",
                                           ifelse(trailbike_pri_wet == "2", "M",
                                                  ifelse(trailbike_pri_wet == "3", "H",
                                                         ifelse(trailbike_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_dry = ifelse(trailbike_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                    substr(trailbike_pri_dry, 1, 1), 
                              ifelse(trailbike_pri_dry == "0", "N",
                                     ifelse(trailbike_pri_dry == "1", "L",
                                           ifelse(trailbike_pri_dry == "2", "M",
                                                  ifelse(trailbike_pri_dry == "3", "H",
                                                         ifelse(trailbike_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_SF = ifelse(trailbike_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                   substr(trailbike_pri_SF, 1, 1), 
                              ifelse(trailbike_pri_SF == "0", "N",
                                     ifelse(trailbike_pri_SF == "1", "L",
                                           ifelse(trailbike_pri_SF == "2", "M",
                                                  ifelse(trailbike_pri_SF == "3", "H",
                                                         ifelse(trailbike_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_dune = ifelse(trailbike_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                     substr(trailbike_pri_dune, 1, 1), 
                              ifelse(trailbike_pri_dune == "0", "N",
                                     ifelse(trailbike_pri_dune == "1", "L",
                                           ifelse(trailbike_pri_dune == "2", "M",
                                                  ifelse(trailbike_pri_dune == "3", "H",
                                                         ifelse(trailbike_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_wet = ifelse(horse_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(horse_pri_wet, 1, 1), 
                              ifelse(horse_pri_wet == "0", "N",
                                     ifelse(horse_pri_wet == "1", "L",
                                           ifelse(horse_pri_wet == "2", "M",
                                                  ifelse(horse_pri_wet == "3", "H",
                                                         ifelse(horse_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_dry = ifelse(horse_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(horse_pri_dry, 1, 1), 
                              ifelse(horse_pri_dry == "0", "N",
                                     ifelse(horse_pri_dry == "1", "L",
                                           ifelse(horse_pri_dry == "2", "M",
                                                  ifelse(horse_pri_dry == "3", "H",
                                                         ifelse(horse_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_SF = ifelse(horse_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(horse_pri_SF, 1, 1), 
                              ifelse(horse_pri_SF == "0", "N",
                                     ifelse(horse_pri_SF == "1", "L",
                                           ifelse(horse_pri_SF == "2", "M",
                                                  ifelse(horse_pri_SF == "3", "H",
                                                         ifelse(horse_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_dune = ifelse(horse_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(horse_pri_dune, 1, 1), 
                              ifelse(horse_pri_dune == "0", "N",
                                     ifelse(horse_pri_dune == "1", "L",
                                           ifelse(horse_pri_dune == "2", "M",
                                                  ifelse(horse_pri_dune == "3", "H",
                                                         ifelse(horse_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_wet = ifelse(stock_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(stock_pri_wet, 1, 1), 
                              ifelse(stock_pri_wet == "0", "N",
                                     ifelse(stock_pri_wet == "1", "L",
                                           ifelse(stock_pri_wet == "2", "M",
                                                  ifelse(stock_pri_wet == "3", "H",
                                                         ifelse(stock_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_dry = ifelse(stock_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(stock_pri_dry, 1, 1), 
                              ifelse(stock_pri_dry == "0", "N",
                                     ifelse(stock_pri_dry == "1", "L",
                                           ifelse(stock_pri_dry == "2", "M",
                                                  ifelse(stock_pri_dry == "3", "H",
                                                         ifelse(stock_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_SF = ifelse(stock_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(stock_pri_SF, 1, 1), 
                              ifelse(stock_pri_SF == "0", "N",
                                     ifelse(stock_pri_SF == "1", "L",
                                           ifelse(stock_pri_SF == "2", "M",
                                                  ifelse(stock_pri_SF == "3", "H",
                                                         ifelse(stock_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_dune = ifelse(stock_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(stock_pri_dune, 1, 1), 
                              ifelse(stock_pri_dune == "0", "N",
                                     ifelse(stock_pri_dune == "1", "L",
                                           ifelse(stock_pri_dune == "2", "M",
                                                  ifelse(stock_pri_dune == "3", "H",
                                                         ifelse(stock_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H"))) %>% 
  # to control for multiple threat surveys per date, summarise by date
  group_by(region, site, season, obs_date, obs_date2) %>% 
  summarise(obs_lon = mean(obs_lon, na.rm = TRUE),
            obs_lat = mean(obs_lat, na.rm = TRUE),
            # in the case of multiple surveys on a single date at a specific 
            # site, take the max humans counted, etc., and the highest level of
            # prints, etc.
            humans = max(humans, na.rm = TRUE),
            humans_wet = max(humans_wet, na.rm = TRUE),
            humans_dry = max(humans_dry, na.rm = TRUE),
            humans_dune = max(humans_dune, na.rm = TRUE),
            humans_SF = max(humans_SF, na.rm = TRUE),
            hoofed_animals = max(hoofed_animals, na.rm = TRUE),
            vehicles = max(vehicles, na.rm = TRUE),
            pred_birds = max(pred_birds, na.rm = TRUE),
            gulls = max(gulls, na.rm = TRUE),
            dogs_off = max(dogs_off, na.rm = TRUE),
            dogs_on = max(dogs_on, na.rm = TRUE),
            dogs = max(dogs, na.rm = TRUE),
            hum_pri_wet = ifelse(all(is.na(hum_pri_wet)), NA, 
                                 levels(hum_pri_wet)[max(as.integer(hum_pri_wet), na.rm = TRUE)]),
            hum_pri_dry = ifelse(all(is.na(hum_pri_dry)), NA, 
                                 levels(hum_pri_dry)[max(as.integer(hum_pri_dry), na.rm = TRUE)]),
            hum_pri_dune = ifelse(all(is.na(hum_pri_dune)), NA, 
                                  levels(hum_pri_dune)[max(as.integer(hum_pri_dune), na.rm = TRUE)]),
            hum_pri_SF = ifelse(all(is.na(hum_pri_SF)), NA, 
                                levels(hum_pri_SF)[max(as.integer(hum_pri_SF), na.rm = TRUE)]),
            fox_pri_wet = ifelse(all(is.na(fox_pri_wet)), NA, 
                                 levels(fox_pri_wet)[max(as.integer(fox_pri_wet), na.rm = TRUE)]),
            fox_pri_dry = ifelse(all(is.na(fox_pri_dry)), NA, 
                                 levels(fox_pri_dry)[max(as.integer(fox_pri_dry), na.rm = TRUE)]),
            fox_pri_dune = ifelse(all(is.na(fox_pri_dune)), NA, 
                                  levels(fox_pri_dune)[max(as.integer(fox_pri_dune), na.rm = TRUE)]),
            fox_pri_SF = ifelse(all(is.na(fox_pri_SF)), NA, 
                                levels(fox_pri_SF)[max(as.integer(fox_pri_SF), na.rm = TRUE)]),
            dog_pri_wet = ifelse(all(is.na(dog_pri_wet)), NA, 
                                 levels(dog_pri_wet)[max(as.integer(dog_pri_wet), na.rm = TRUE)]),
            dog_pri_dry = ifelse(all(is.na(dog_pri_dry)), NA, 
                                 levels(dog_pri_dry)[max(as.integer(dog_pri_dry), na.rm = TRUE)]),
            dog_pri_dune = ifelse(all(is.na(dog_pri_dune)), NA, 
                                  levels(dog_pri_dune)[max(as.integer(dog_pri_dune), na.rm = TRUE)]),
            dog_pri_SF = ifelse(all(is.na(dog_pri_SF)), NA, 
                                levels(dog_pri_SF)[max(as.integer(dog_pri_SF), na.rm = TRUE)]),
            vehicle_pri_wet = ifelse(all(is.na(vehicle_pri_wet)), NA, 
                                     levels(vehicle_pri_wet)[max(as.integer(vehicle_pri_wet), na.rm = TRUE)]),
            vehicle_pri_dry = ifelse(all(is.na(vehicle_pri_dry)), NA, 
                                     levels(vehicle_pri_dry)[max(as.integer(vehicle_pri_dry), na.rm = TRUE)]),
            vehicle_pri_dune = ifelse(all(is.na(vehicle_pri_dune)), NA, 
                                      levels(vehicle_pri_dune)[max(as.integer(vehicle_pri_dune), na.rm = TRUE)]),
            vehicle_pri_SF = ifelse(all(is.na(vehicle_pri_SF)), NA, 
                                    levels(vehicle_pri_SF)[max(as.integer(vehicle_pri_SF), na.rm = TRUE)]),
            trailbike_pri_wet = ifelse(all(is.na(trailbike_pri_wet)), NA, 
                                       levels(trailbike_pri_wet)[max(as.integer(trailbike_pri_wet), na.rm = TRUE)]),
            trailbike_pri_dry = ifelse(all(is.na(trailbike_pri_dry)), NA, 
                                       levels(trailbike_pri_dry)[max(as.integer(trailbike_pri_dry), na.rm = TRUE)]),
            trailbike_pri_dune = ifelse(all(is.na(trailbike_pri_dune)), NA, 
                                        levels(trailbike_pri_dune)[max(as.integer(trailbike_pri_dune), na.rm = TRUE)]),
            trailbike_pri_SF = ifelse(all(is.na(trailbike_pri_SF)), NA, 
                                      levels(trailbike_pri_SF)[max(as.integer(trailbike_pri_SF), na.rm = TRUE)]),
            horse_pri_wet = ifelse(all(is.na(horse_pri_wet)), NA, 
                                   levels(horse_pri_wet)[max(as.integer(horse_pri_wet), na.rm = TRUE)]),
            horse_pri_dry = ifelse(all(is.na(horse_pri_dry)), NA, 
                                   levels(horse_pri_dry)[max(as.integer(horse_pri_dry), na.rm = TRUE)]),
            horse_pri_dune = ifelse(all(is.na(horse_pri_dune)), NA, 
                                    levels(horse_pri_dune)[max(as.integer(horse_pri_dune), na.rm = TRUE)]),
            horse_pri_SF = ifelse(all(is.na(horse_pri_SF)), NA, 
                                  levels(horse_pri_SF)[max(as.integer(horse_pri_SF), na.rm = TRUE)]),
            stock_pri_wet = ifelse(all(is.na(stock_pri_wet)), NA, 
                                   levels(stock_pri_wet)[max(as.integer(stock_pri_wet), na.rm = TRUE)]),
            stock_pri_dry = ifelse(all(is.na(stock_pri_dry)), NA, 
                                   levels(stock_pri_dry)[max(as.integer(stock_pri_dry), na.rm = TRUE)]),
            stock_pri_dune = ifelse(all(is.na(stock_pri_dune)), NA, 
                                    levels(stock_pri_dune)[max(as.integer(stock_pri_dune), na.rm = TRUE)]),
            stock_pri_SF = ifelse(all(is.na(stock_pri_SF)), NA, 
                                  levels(stock_pri_SF)[max(as.integer(stock_pri_SF), na.rm = TRUE)])) %>%
  # make the print variables a factor
  mutate_at(vars(hum_pri_wet, hum_pri_dry, hum_pri_dune, hum_pri_SF,
                 dog_pri_wet, dog_pri_dry, dog_pri_dune, dog_pri_SF,
                 fox_pri_wet, fox_pri_dry, fox_pri_dune, fox_pri_SF,
                 vehicle_pri_wet, vehicle_pri_dry, vehicle_pri_dune, vehicle_pri_SF,
                 trailbike_pri_wet, trailbike_pri_dry, trailbike_pri_dune, trailbike_pri_SF,
                 horse_pri_wet, horse_pri_dry, horse_pri_dune, horse_pri_SF,
                 stock_pri_wet, stock_pri_dry, stock_pri_dune, stock_pri_SF),
            ~ as.factor(.)) %>% 
  # specify the level order of the print variables
  mutate_at(vars(hum_pri_wet, hum_pri_dry, hum_pri_dune, hum_pri_SF,
                 dog_pri_wet, dog_pri_dry, dog_pri_dune, dog_pri_SF,
                 fox_pri_wet, fox_pri_dry, fox_pri_dune, fox_pri_SF,
                 vehicle_pri_wet, vehicle_pri_dry, vehicle_pri_dune, vehicle_pri_SF,
                 trailbike_pri_wet, trailbike_pri_dry, trailbike_pri_dune, trailbike_pri_SF,
                 horse_pri_wet, horse_pri_dry, horse_pri_dune, horse_pri_SF,
                 stock_pri_wet, stock_pri_dry, stock_pri_dune, stock_pri_SF),
            ~ factor(., levels = c("L", "M", "H"))) %>% 
  # summarize the print variables across the wet, dry, dune, and sign/fence micro habitats
  mutate(hum_pri = ifelse(all(is.na(hum_pri_wet)) && all(is.na(hum_pri_dry)) && 
                            all(is.na(hum_pri_dune)) && all(is.na(hum_pri_SF)), NA,
                          pmax(as.integer(hum_pri_wet), as.integer(hum_pri_dry), 
                               as.integer(hum_pri_dune), as.integer(hum_pri_SF), na.rm = TRUE)),
         fox_pri = ifelse(all(is.na(fox_pri_wet)) && all(is.na(fox_pri_dry)) && 
                            all(is.na(fox_pri_dune)) && all(is.na(fox_pri_SF)), NA,
                          pmax(as.integer(fox_pri_wet), as.integer(fox_pri_dry), 
                               as.integer(fox_pri_dune), as.integer(fox_pri_SF), na.rm = TRUE)),
         dog_pri = ifelse(all(is.na(dog_pri_wet)) && all(is.na(dog_pri_dry)) && 
                            all(is.na(dog_pri_dune)) && all(is.na(dog_pri_SF)), NA,
                          pmax(as.integer(dog_pri_wet), as.integer(dog_pri_dry), 
                               as.integer(dog_pri_dune), as.integer(dog_pri_SF), na.rm = TRUE)),
         vehicle_pri = ifelse(all(is.na(vehicle_pri_wet)) && all(is.na(vehicle_pri_dry)) && 
                                all(is.na(vehicle_pri_dune)) && all(is.na(vehicle_pri_SF)) &&
                              all(is.na(trailbike_pri_wet)) && all(is.na(trailbike_pri_dry)) && 
                                all(is.na(trailbike_pri_dune)) && all(is.na(trailbike_pri_SF)), NA,
                              pmax(as.integer(vehicle_pri_wet), as.integer(vehicle_pri_dry), 
                                   as.integer(vehicle_pri_dune), as.integer(vehicle_pri_SF), 
                                   as.integer(trailbike_pri_wet), as.integer(trailbike_pri_dry), 
                                   as.integer(trailbike_pri_dune), as.integer(trailbike_pri_SF), na.rm = TRUE)),
         hoofed_pri = ifelse(all(is.na(horse_pri_wet)) && all(is.na(horse_pri_dry)) && 
                               all(is.na(horse_pri_dune)) && all(is.na(horse_pri_SF)) &&
                             all(is.na(stock_pri_wet)) && all(is.na(stock_pri_dry)) && 
                               all(is.na(stock_pri_dune)) && all(is.na(stock_pri_SF)), NA,
                             pmax(as.integer(horse_pri_wet), as.integer(horse_pri_dry), 
                                  as.integer(horse_pri_dune), as.integer(horse_pri_SF), 
                                  as.integer(stock_pri_wet), as.integer(stock_pri_dry), 
                                  as.integer(stock_pri_dune), as.integer(stock_pri_SF), na.rm = TRUE))) %>% 
  # consolidate the threat data into a clean dataframe
  dplyr::select(region, site, season, obs_date, obs_date2, obs_lon, obs_lat, 
         humans, vehicles, dogs, dogs_on, dogs_off, hoofed_animals, pred_birds,
         gulls, hum_pri, fox_pri, dog_pri, vehicle_pri, hoofed_pri) %>% 
  ungroup()

Visual inspection of threat data

determine the 99% quantile limit for each threat (i.e., to remove outlier data) - shown as the red vertical line here

Code
# determine the 99% quantile limit for each threat (i.e., to remove outlier data)
threat_data_99_ql <- 
  threat_data_ %>% 
  summarise_at(c("humans", "vehicles", "dogs", "dogs_on", "dogs_off", "hoofed_animals", "pred_birds", "gulls"), 
               ~ quantile(.x, probs = c(0.99)))

threat_data_99_ql
# A tibble: 1 × 8
  humans vehicles  dogs dogs_on dogs_off hoofed_animals pred_birds gulls
   <dbl>    <dbl> <dbl>   <dbl>    <dbl>          <dbl>      <dbl> <dbl>
1     65        6    14       7       10              2          8   200
Code
# check histograms of threat data while inspecting the 99% cut-off
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(humans + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$humans[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(pred_birds + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$pred_birds[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(gulls + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$pred_birds[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(vehicles))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$vehicles[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs_off + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs_off[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs_on + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs_on[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(hoofed_animals)) +
  geom_vline(xintercept = as.numeric(threat_data_99_ql$hoofed_animals[1]), color = "red") +
  luke_theme

Extract holidays (an index of human disturbance)

Code
# extract public holidays and merge them to the threat data
#### FP ----
FP_holidays <-
  bind_rows(
    holiday_aus(2009, state = "SA"),
    holiday_aus(2010, state = "SA"),
    holiday_aus(2011, state = "SA"),
    holiday_aus(2012, state = "SA"),
    holiday_aus(2013, state = "SA"),
    holiday_aus(2014, state = "SA"),
    holiday_aus(2015, state = "SA"),
    holiday_aus(2016, state = "SA"),
    holiday_aus(2017, state = "SA"),
    holiday_aus(2018, state = "SA"),
    holiday_aus(2019, state = "SA"),
    holiday_aus(2020, state = "SA"),
    holiday_aus(2021, state = "SA")) %>% 
  mutate(event = holiday) %>% 
  mutate(region = "FP",
         end_date = date) %>% 
  rename(start_date = date) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year + 1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

SA_start_end_holidays <- 
  read_excel("data/final/final_final/School holiday dates.xlsx",
             sheet = "SA Sch. Hol Dates", 
             col_types = "text") %>% 
  separate(`Autumn school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(autumn_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         autumn_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Winter school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(winter_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         winter_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Spring school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(spring_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         spring_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Summer school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(summer_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         summer_end = as.Date(paste(as.character(as.numeric(Year)+1), new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(Year:Source))

FP_start_school_holidays <- 
  SA_start_end_holidays %>% 
  select(autumn_start, winter_start, spring_start, summer_start) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_start")) %>% 
  mutate(region = "FP") %>% 
  rename(start_date = value) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

FP_school_holidays <- 
  SA_start_end_holidays %>% 
  select(autumn_end, winter_end, spring_end, summer_end) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_end")) %>% 
  rename(end_date = value) %>% 
  mutate(year = year(end_date)) %>% 
  mutate(season = ifelse(month(end_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(end_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4)))) %>% 
  left_join(FP_start_school_holidays, ., by = c("season", "event")) %>% 
  mutate(event = paste(event, "school", sep = "_")) %>% 
  select(-c(year.x, year.y))

FP_holidays <- 
  bind_rows(FP_school_holidays, FP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date)

#### MP ----
MP_holidays <-
  bind_rows(
    holiday_aus(2006, state = "VIC"),
    holiday_aus(2007, state = "VIC"),
    holiday_aus(2008, state = "VIC"),
    holiday_aus(2009, state = "VIC"),
    holiday_aus(2010, state = "VIC"),
    holiday_aus(2011, state = "VIC"),
    holiday_aus(2012, state = "VIC"),
    holiday_aus(2013, state = "VIC"),
    holiday_aus(2014, state = "VIC"),
    holiday_aus(2015, state = "VIC"),
    holiday_aus(2016, state = "VIC"),
    holiday_aus(2017, state = "VIC"),
    holiday_aus(2018, state = "VIC"),
    holiday_aus(2019, state = "VIC"),
    holiday_aus(2020, state = "VIC"),
    holiday_aus(2021, state = "VIC")) %>% 
  mutate(event = holiday) %>% 
  mutate(region = "MP",
         end_date = date) %>% 
  rename(start_date = date) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year + 1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

VIC_start_end_holidays <- 
  read_excel("data/final/final_final/School holiday dates.xlsx",
             sheet = "VIC Sch. Hol. Dates", 
             col_types = "text") %>% 
  separate(`Autumn school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(autumn_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         autumn_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Winter school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(winter_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         winter_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Spring school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(spring_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         spring_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Summer school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(summer_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         summer_end = as.Date(paste(as.character(as.numeric(Year)+1), new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(Year:Source))

MP_start_school_holidays <- 
  VIC_start_end_holidays %>% 
  select(autumn_start, winter_start, spring_start, summer_start) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_start")) %>% 
  mutate(region = "FP") %>% 
  rename(start_date = value) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

MP_school_holidays <- 
  VIC_start_end_holidays %>% 
  select(autumn_end, winter_end, spring_end, summer_end) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_end")) %>% 
  rename(end_date = value) %>% 
  mutate(year = year(end_date)) %>% 
  mutate(season = ifelse(month(end_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(end_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4)))) %>% 
  left_join(MP_start_school_holidays, ., by = c("season", "event")) %>% 
  mutate(event = paste(event, "school", sep = "_")) %>% 
  select(-c(year.x, year.y)) %>% arrange(start_date)

MP_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date)

BSC_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date) %>% 
  mutate(region = "BSC")

holidays <- 
  bind_rows(FP_holidays, BSC_holidays, MP_holidays)# %>% 
  # pivot_longer(-c(season:holiday), names_to = "start_end", values_to = "date")

Extract Weekdays (another index of human disturbance)

Code
threat_data__ <-
  threat_data_ %>% 
  mutate(season_site = paste(season, site, sep = "_"),
         weekday = factor(as.factor(weekdays(obs_date)), 
                          levels = c("Monday", "Tuesday", "Wednesday", 
                                     "Thursday", "Friday", "Saturday", 
                                     "Sunday"))) %>% 
  rename(date = obs_date) %>% 
  left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
  mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
  # dplyr::select(region, season, site, date, start_date, end_date, event, holiday) %>% distinct() %>% 
  group_by(region, season, site, date) %>% 
  mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
  dplyr::select(-c(event, start_date, end_date)) %>% 
  distinct() %>% 
  ungroup() %>% 
  mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                             c("Saturday", "Sunday"), "funday", "workday")) %>% 
  mutate(funday = ifelse(day_type == "funday", 1, 0)) %>% 
  mutate(humans_ = ifelse(humans > as.numeric(threat_data_99_ql$humans[1]), NA, humans),
         vehicles_ = ifelse(vehicles > as.numeric(threat_data_99_ql$vehicles[1]), NA, vehicles),
         dogs_ = ifelse(dogs > as.numeric(threat_data_99_ql$dogs[1]), NA, dogs),
         dogs_off_ = ifelse(dogs_off > as.numeric(threat_data_99_ql$dogs_off[1]), NA, dogs_off),
         dogs_on_ = ifelse(dogs_on > as.numeric(threat_data_99_ql$dogs_on[1]), NA, dogs_on),
         hoofed_animals_ = ifelse(hoofed_animals > as.numeric(threat_data_99_ql$hoofed_animals[1]), NA, hoofed_animals),
         pred_birds_ = ifelse(pred_birds > as.numeric(threat_data_99_ql$pred_birds[1]), NA, pred_birds),
         gulls_ = ifelse(gulls > as.numeric(threat_data_99_ql$gulls[1]), NA, pred_birds)) %>% 
  mutate(weekdayN = as.numeric(weekday) - 1) %>% 
  mutate(weekdayC = circular::circular(weekdayN, type = "angles", units = "radians")) %>% 
  filter(!is.na(weekday))

threat_data__ %>% 
  ggplot() +
  geom_histogram(aes(funday)) +
  # geom_vline(xintercept = log(10), color = "red") +
  luke_theme

test if weekends and holidays have more threat counts than other days using zero-inflated models. For all threats, there are more counted on weekends and holidays than during the week, except for vehicles (which occur randomly across the week)

Code
#### test if weekends and holidays have more threat counts than other days
# use a zero-inflated model (https://stats.oarc.ucla.edu/r/dae/zip/)

# for all threats, there are more counted on weekends and holidays than during the week,
# except for vehicles (which occur randomly across the week)
mod_hum_zi <- pscl::zeroinfl(humans_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_hum_zi)

Call:
pscl::zeroinfl(formula = humans_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-1.1167 -0.7764 -0.7764  0.1435 19.1555 

Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      2.283190   0.003276   696.8   <2e-16 ***
day_typeworkday -0.537083   0.005252  -102.3   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     -0.45390    0.01646  -27.57   <2e-16 ***
day_typeworkday  0.68819    0.02102   32.74   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 6 
Log-likelihood: -1.349e+05 on 4 Df
Code
mod_dogs_zi <- pscl::zeroinfl(dogs_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_zi)

Call:
pscl::zeroinfl(formula = dogs_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.6585 -0.4541 -0.4541 -0.1849  9.6045 

Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.279992   0.007178  178.33   <2e-16 ***
day_typeworkday -0.287836   0.011567  -24.89   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.46178    0.01689   27.34   <2e-16 ***
day_typeworkday  0.72214    0.02337   30.91   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 7 
Log-likelihood: -4.849e+04 on 4 Df
Code
mod_dogs_on_zi <- pscl::zeroinfl(dogs_on_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_on_zi)

Call:
pscl::zeroinfl(formula = dogs_on_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.4619 -0.4619 -0.3005 -0.3005 10.4039 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.62654    0.01390   45.08   <2e-16 ***
day_typeworkday -0.30974    0.02433  -12.73   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.99540    0.02121   46.93   <2e-16 ***
day_typeworkday  0.79401    0.03231   24.57   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 9 
Log-likelihood: -2.531e+04 on 4 Df
Code
mod_dogs_off_zi <- pscl::zeroinfl(dogs_off_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_off_zi)

Call:
pscl::zeroinfl(formula = dogs_off_ ~ day_type, data = threat_data__, 
    dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.5282 -0.5282 -0.3830 -0.3830  8.6505 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.02943    0.00973  105.81   <2e-16 ***
day_typeworkday -0.19020    0.01507  -12.62   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.86628    0.01852   46.79   <2e-16 ***
day_typeworkday  0.62880    0.02594   24.24   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 7 
Log-likelihood: -3.604e+04 on 4 Df
Code
mod_pred_birds_zi <- pscl::zeroinfl(pred_birds_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_pred_birds_zi)

Call:
pscl::zeroinfl(formula = pred_birds_ ~ day_type, data = threat_data__, 
    dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.3224 -0.3224 -0.3204 -0.3204  7.5270 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     0.912069   0.015806  57.704   <2e-16 ***
day_typeworkday 0.009919   0.020374   0.487    0.626    

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.88333    0.02510  75.042   <2e-16 ***
day_typeworkday  0.01647    0.03241   0.508    0.611    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 8 
Log-likelihood: -2.291e+04 on 4 Df
Code
mod_gulls_zi <- pscl::zeroinfl(gulls_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_gulls_zi)

Call:
pscl::zeroinfl(formula = gulls_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.3386 -0.3386 -0.3385 -0.3385 74.5527 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.27293    0.01230 103.515   <2e-16 ***
day_typeworkday  0.01718    0.01578   1.088    0.276    

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.88630    0.02405  78.433   <2e-16 ***
day_typeworkday  0.00506    0.03098   0.163     0.87    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 7 
Log-likelihood: -3.079e+04 on 4 Df
Code
mod_vehicles_zi <- pscl::zeroinfl(vehicles_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_vehicles_zi)

Call:
pscl::zeroinfl(formula = vehicles_ ~ day_type, data = threat_data__, 
    dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.1515 -0.1515 -0.1141 -0.1141 16.7320 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     0.766281   0.035562  21.547   <2e-16 ***
day_typeworkday 0.004824   0.051951   0.093    0.926    

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      3.38138    0.04899  69.022  < 2e-16 ***
day_typeworkday  0.57379    0.07135   8.042 8.83e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 9 
Log-likelihood: -5486 on 4 Df

Fit circular GAM to weekly count data to assess trends over the week.

how do human counts vary over the week?

Code
#### Fit circular GAM to weekly count data ----
mod_hum <- 
  mgcv::gam(humans_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_hum)

Family: gaussian 
Link function: identity 

Formula:
humans_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  3.89799    0.03891   100.2   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.906      5 95.09  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.0119   Deviance explained =  1.2%
GCV = 59.684  Scale est. = 59.675    n = 39426
Code
# estimate model predictions 
newdata_weekdays <- 
  data.frame(weekdayN = seq(0, 6))

# plot the weekly variation in the human counts
mod_hum_fits <- 
  predict(mod_hum, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_hum_predicts <-  
  data.frame(newdata_weekdays, mod_hum_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>%
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(humans_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1, color = "grey70"
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(humans_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA, color = "grey70"
    ) +
  # geom_smooth(aes(x = as.numeric(weekday), y = humans_), 
  #             method = lm, 
  #             formula = y ~ splines::bs(x, 5)) +
  geom_ribbon(data = mod_hum_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_hum_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  luke_theme +
  xlab("day of the week") +
  ylab("number of humans counted (log)")

how do dog counts vary over the week?

Code
mod_dogs <- 
  mgcv::gam(dogs_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs)

Family: gaussian 
Link function: identity 

Formula:
dogs_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.93086    0.01054   88.28   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.567      5 32.36  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.00407   Deviance explained = 0.418%
GCV = 4.3841  Scale est. = 4.3835    n = 39425
Code
# plot the weekly variation in the dog counts
mod_dogs_fits <- 
  predict(mod_dogs, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_dogs_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of dogs counted (log)")

how do dogs on leash counts vary over the week?

Code
mod_dogs_on <- 
  mgcv::gam(dogs_on_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs_on)

Family: gaussian 
Link function: identity 

Formula:
dogs_on_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.318054   0.004606   69.06   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.586      5 28.13  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.00352   Deviance explained = 0.364%
GCV = 0.83685  Scale est. = 0.83673   n = 39443
Code
# plot the weekly variation in the dog on leash counts
mod_dogs_on_fits <- 
  predict(mod_dogs_on, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_dogs_on_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_on_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_on_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_on_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_on_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_on_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_on_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of dogs on leashes counted (log)")

how do dogs off leash counts vary over the week?

Code
mod_dogs_off <- 
  mgcv::gam(dogs_off_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs_off)

Family: gaussian 
Link function: identity 

Formula:
dogs_off_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.583669   0.007458   78.26   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.117      5 21.01  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.00265   Deviance explained = 0.275%
GCV = 2.1953  Scale est. = 2.1951    n = 39459
Code
# plot the weekly variation in the dog off leash counts
mod_dogs_off_fits <- 
  predict(mod_dogs_off, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_dogs_off_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_off_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_off_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_off_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_off_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_off_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_off_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of dogs off leashes counted (log)")

how do corvid counts vary over the week?

Code
mod_pred_birds <- 
  mgcv::gam(pred_birds_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_pred_birds)

Family: gaussian 
Link function: identity 

Formula:
pred_birds_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.327760   0.005354   61.22   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value  
s(weekdayN) 4.129      5 2.374  0.0147 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.000248   Deviance explained = 0.0352%
GCV = 1.1316  Scale est. = 1.1314    n = 39474
Code
# plot the weekly variation in the predatory bird counts
mod_pred_birds_fits <- 
  predict(mod_pred_birds, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_pred_birds_predicts <-  
  data.frame(newdata_weekdays, mod_pred_birds_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(pred_birds_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(pred_birds_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_pred_birds_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_pred_birds_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = pred_birds_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of corvids counted (log)")

how do gulls counts vary over the week?

Code
mod_pred_birds <- 
  mgcv::gam(gulls_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_pred_birds)

Family: gaussian 
Link function: identity 

Formula:
gulls_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.47387    0.01148   41.27   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value  
s(weekdayN) 3.727      5 2.149  0.0162 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.000237   Deviance explained = 0.0332%
GCV = 5.2074  Scale est. = 5.2067    n = 39496
Code
# plot the weekly variation in the predatory bird counts
mod_gulls_fits <- 
  predict(mod_pred_birds, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_gulls_predicts <-  
  data.frame(newdata_weekdays, mod_gulls_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(gulls_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(gulls_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_gulls_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_gulls_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = gulls_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of gulls counted (log)")

how do vehicle counts vary over the week?

Code
mod_vehicles <- 
  mgcv::gam(vehicles_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_vehicles)

Family: gaussian 
Link function: identity 

Formula:
vehicles_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.052537   0.002113   24.86   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value  
s(weekdayN) 1.445      5 0.992  0.0213 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.000135   Deviance explained = 0.0171%
GCV = 0.17618  Scale est. = 0.17617   n = 39458
Code
# plot the weekly variation in the vehicle counts
mod_vehicles_fits <- 
  predict(mod_vehicles, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_vehicles_predicts <-  
  data.frame(newdata_weekdays, mod_vehicles_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = vehicles_),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = vehicles_),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_vehicles_predicts,
              aes(x = as.numeric(weekday), ymin = lower, ymax = upper)) +
  geom_line(data = mod_vehicles_predicts, aes(x = as.numeric(weekday), y = fit), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = vehicles_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of vehicles counted")

Inspect the weekly variation in human prints

Code
# plot the weekly variation in the human print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = hum_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = hum_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = hum_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of human prints recorded")

Inspect the weekly variation in dog prints

Code
# plot the weekly variation in the dog print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = dog_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = dog_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = dog_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of dogs prints recorded")

Inspect the weekly variation in vehicle prints

Code
# plot the weekly variation in the vehicle print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = vehicle_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = vehicle_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = vehicle_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of vehicle prints recorded")

Inspect the weekly variation in fox prints

Code
# plot the weekly variation in the fox print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = fox_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = fox_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = fox_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of fox prints recorded")

check correlation between counts of the various threats

Code
# check correlation between humans counts
threat_data__ %>% 
  dplyr::select(humans_, vehicles_, dogs_, pred_birds_) %>% 
  na.omit() %>% 
  cor() %>% 
  corrplot(type = "upper", method = "number", tl.srt = 45)

Code
# relationship between human counts and dog counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = dogs_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = dogs_)) +#, method = lm, formula = y ~ splines::bs(x, 2)) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of dogs counted")

Code
# relationship between human counts and corvid counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = pred_birds_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = pred_birds_)) +#, method = lm) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of corvids counted")

Code
# relationship between human counts and gull counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = gulls_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = gulls_)) +#, method = lm) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of gulls counted")

Code
# relationship between human counts and vehicle counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = vehicles_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = vehicles_)) + #, method = lm, formula = y ~ splines::bs(x, 2)) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of vehicles counted")

Code
# determine which territories are in the threat data and the nest data
sites_intersect_FP <- 
  inner_join(nest_data_FP, threat_data__ %>% filter(region == "FP"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))

sites_intersect_MP <- 
  inner_join(nest_data_MP, threat_data__ %>% filter(region == "MP"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))

sites_intersect_BSC <- 
  inner_join(nest_data_BSC, threat_data__ %>% filter(region == "BSC"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))
Code
##### Fleurieu Peninsula: summarise threat data
nest_data_FP_with_threat_data <- 
  nest_data_FP %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_FP$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)

FP_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "FP") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_FP$season_site) %>%
  ungroup()

for(i in 1:nrow(nest_data_FP_with_threat_data)){
  FirstFound <- nest_data_FP_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_FP_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_FP_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_FP_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_FP_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_FP_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_FP_with_threat_data$site[i])
  season_ <- as.character(nest_data_FP_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "FP") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  FP_threat_data_subset_ <- 
    FP_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(FP_threat_data_subset_) > 0){
    avgeraged_threats <-
      FP_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_FP_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_FP_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_FP_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_FP_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_FP_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_FP_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_FP_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_FP_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_FP_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_FP_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_FP_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_FP_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_FP_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_FP_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_FP_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_FP_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_FP_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_FP_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_FP_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_FP_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_FP_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_FP_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_FP_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_FP_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_FP_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_FP_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_FP_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_FP_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_FP_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_FP_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_FP_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_FP_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_FP_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_FP_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days

    
  }else{
    nest_data_FP_with_threat_data$hum_a[i] <- NA
    nest_data_FP_with_threat_data$veh_a[i] <- NA
    nest_data_FP_with_threat_data$dog_a[i] <- NA
    nest_data_FP_with_threat_data$don_a[i] <- NA
    nest_data_FP_with_threat_data$dof_a[i] <- NA
    nest_data_FP_with_threat_data$hof_a[i] <- NA
    nest_data_FP_with_threat_data$pbd_a[i] <- NA
    nest_data_FP_with_threat_data$gul_a[i] <- NA
    nest_data_FP_with_threat_data$hum_m[i] <- NA
    nest_data_FP_with_threat_data$veh_m[i] <- NA
    nest_data_FP_with_threat_data$dog_m[i] <- NA
    nest_data_FP_with_threat_data$don_m[i] <- NA
    nest_data_FP_with_threat_data$dof_m[i] <- NA
    nest_data_FP_with_threat_data$hof_m[i] <- NA
    nest_data_FP_with_threat_data$pbd_m[i] <- NA
    nest_data_FP_with_threat_data$gul_m[i] <- NA
    nest_data_FP_with_threat_data$hum_b[i] <- NA
    nest_data_FP_with_threat_data$veh_b[i] <- NA
    nest_data_FP_with_threat_data$dog_b[i] <- NA
    nest_data_FP_with_threat_data$don_b[i] <- NA
    nest_data_FP_with_threat_data$dof_b[i] <- NA
    nest_data_FP_with_threat_data$pbd_b[i] <- NA
    nest_data_FP_with_threat_data$gul_b[i] <- NA
    nest_data_FP_with_threat_data$hof_b[i] <- NA
    nest_data_FP_with_threat_data$hum_p[i] <- NA
    nest_data_FP_with_threat_data$veh_p[i] <- NA
    nest_data_FP_with_threat_data$dog_p[i] <- NA
    nest_data_FP_with_threat_data$hof_p[i] <- NA
    nest_data_FP_with_threat_data$fox_p[i] <- NA
    nest_data_FP_with_threat_data$n_surveys[i] <- 0
    nest_data_FP_with_threat_data$days_active[i] <- days_active
    nest_data_FP_with_threat_data$halfway[i] <- halfway
    nest_data_FP_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_FP_with_threat_data$fundays[i] <- NA
  }
}
Code
##### Mornington Peninsula: summarise threat data
nest_data_MP_with_threat_data <- 
  nest_data_MP %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_MP$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)

MP_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "MP") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_MP$season_site) %>%
  ungroup()

for(i in 1:nrow(nest_data_MP_with_threat_data)){
  FirstFound <- nest_data_MP_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_MP_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_MP_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_MP_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_MP_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_MP_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_MP_with_threat_data$site[i])
  season_ <- as.character(nest_data_MP_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "MP") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  MP_threat_data_subset_ <- 
    MP_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(MP_threat_data_subset_) > 0){
    avgeraged_threats <-
      MP_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_MP_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_MP_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_MP_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_MP_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_MP_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_MP_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_MP_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_MP_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_MP_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_MP_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_MP_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_MP_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_MP_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_MP_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_MP_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_MP_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_MP_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_MP_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_MP_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_MP_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_MP_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_MP_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_MP_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_MP_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_MP_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_MP_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_MP_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_MP_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_MP_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_MP_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_MP_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_MP_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_MP_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_MP_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days

    
  }else{
    nest_data_MP_with_threat_data$hum_a[i] <- NA
    nest_data_MP_with_threat_data$veh_a[i] <- NA
    nest_data_MP_with_threat_data$dog_a[i] <- NA
    nest_data_MP_with_threat_data$don_a[i] <- NA
    nest_data_MP_with_threat_data$dof_a[i] <- NA
    nest_data_MP_with_threat_data$hof_a[i] <- NA
    nest_data_MP_with_threat_data$pbd_a[i] <- NA
    nest_data_MP_with_threat_data$gul_a[i] <- NA
    nest_data_MP_with_threat_data$hum_m[i] <- NA
    nest_data_MP_with_threat_data$veh_m[i] <- NA
    nest_data_MP_with_threat_data$dog_m[i] <- NA
    nest_data_MP_with_threat_data$don_m[i] <- NA
    nest_data_MP_with_threat_data$dof_m[i] <- NA
    nest_data_MP_with_threat_data$hof_m[i] <- NA
    nest_data_MP_with_threat_data$pbd_m[i] <- NA
    nest_data_MP_with_threat_data$gul_m[i] <- NA
    nest_data_MP_with_threat_data$hum_b[i] <- NA
    nest_data_MP_with_threat_data$veh_b[i] <- NA
    nest_data_MP_with_threat_data$dog_b[i] <- NA
    nest_data_MP_with_threat_data$don_b[i] <- NA
    nest_data_MP_with_threat_data$dof_b[i] <- NA
    nest_data_MP_with_threat_data$pbd_b[i] <- NA
    nest_data_MP_with_threat_data$gul_b[i] <- NA
    nest_data_MP_with_threat_data$hof_b[i] <- NA
    nest_data_MP_with_threat_data$hum_p[i] <- NA
    nest_data_MP_with_threat_data$veh_p[i] <- NA
    nest_data_MP_with_threat_data$dog_p[i] <- NA
    nest_data_MP_with_threat_data$hof_p[i] <- NA
    nest_data_MP_with_threat_data$fox_p[i] <- NA
    nest_data_MP_with_threat_data$n_surveys[i] <- 0
    nest_data_MP_with_threat_data$days_active[i] <- days_active
    nest_data_MP_with_threat_data$halfway[i] <- halfway
    nest_data_MP_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_MP_with_threat_data$fundays[i] <- NA
  }
}
Code
##### Bellarine / Surf Coast: summarise threat data
nest_data_BSC_with_threat_data <- 
  nest_data_BSC %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_BSC$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)

BSC_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "BSC") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_BSC$season_site) %>%
  ungroup()

for(i in 1:nrow(nest_data_BSC_with_threat_data)){
  FirstFound <- nest_data_BSC_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_BSC_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_BSC_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_BSC_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_BSC_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_BSC_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_BSC_with_threat_data$site[i])
  season_ <- as.character(nest_data_BSC_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "BSC") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  BSC_threat_data_subset_ <- 
    BSC_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(BSC_threat_data_subset_) > 0){
    avgeraged_threats <-
      BSC_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_BSC_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_BSC_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_BSC_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_BSC_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_BSC_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_BSC_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_BSC_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_BSC_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_BSC_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_BSC_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_BSC_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_BSC_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_BSC_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_BSC_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_BSC_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_BSC_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_BSC_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_BSC_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_BSC_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_BSC_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_BSC_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_BSC_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_BSC_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_BSC_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_BSC_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_BSC_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_BSC_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_BSC_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_BSC_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_BSC_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_BSC_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_BSC_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_BSC_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_BSC_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days

    
  }else{
    nest_data_BSC_with_threat_data$hum_a[i] <- NA
    nest_data_BSC_with_threat_data$veh_a[i] <- NA
    nest_data_BSC_with_threat_data$dog_a[i] <- NA
    nest_data_BSC_with_threat_data$don_a[i] <- NA
    nest_data_BSC_with_threat_data$dof_a[i] <- NA
    nest_data_BSC_with_threat_data$hof_a[i] <- NA
    nest_data_BSC_with_threat_data$pbd_a[i] <- NA
    nest_data_BSC_with_threat_data$gul_a[i] <- NA
    nest_data_BSC_with_threat_data$hum_m[i] <- NA
    nest_data_BSC_with_threat_data$veh_m[i] <- NA
    nest_data_BSC_with_threat_data$dog_m[i] <- NA
    nest_data_BSC_with_threat_data$don_m[i] <- NA
    nest_data_BSC_with_threat_data$dof_m[i] <- NA
    nest_data_BSC_with_threat_data$hof_m[i] <- NA
    nest_data_BSC_with_threat_data$pbd_m[i] <- NA
    nest_data_BSC_with_threat_data$gul_m[i] <- NA
    nest_data_BSC_with_threat_data$hum_b[i] <- NA
    nest_data_BSC_with_threat_data$veh_b[i] <- NA
    nest_data_BSC_with_threat_data$dog_b[i] <- NA
    nest_data_BSC_with_threat_data$don_b[i] <- NA
    nest_data_BSC_with_threat_data$dof_b[i] <- NA
    nest_data_BSC_with_threat_data$pbd_b[i] <- NA
    nest_data_BSC_with_threat_data$gul_b[i] <- NA
    nest_data_BSC_with_threat_data$hof_b[i] <- NA
    nest_data_BSC_with_threat_data$hum_p[i] <- NA
    nest_data_BSC_with_threat_data$veh_p[i] <- NA
    nest_data_BSC_with_threat_data$dog_p[i] <- NA
    nest_data_BSC_with_threat_data$hof_p[i] <- NA
    nest_data_BSC_with_threat_data$fox_p[i] <- NA
    nest_data_BSC_with_threat_data$n_surveys[i] <- 0
    nest_data_BSC_with_threat_data$days_active[i] <- days_active
    nest_data_BSC_with_threat_data$halfway[i] <- halfway
    nest_data_BSC_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_BSC_with_threat_data$fundays[i] <- NA
  }
}

remove outlier data and those with very infrequent threat surveys (cut off: visited at least once per week)

Code
##### remove outlier data and those with very infrequent threat surveys
nest_data_with_threat_data <-
  bind_rows(nest_data_FP_with_threat_data,
            nest_data_MP_with_threat_data,
            nest_data_BSC_with_threat_data) %>% 
  filter(n_surveys > 0) %>% 
  # mutate(dof_b = ifelse(dof_b == 1, "Y", "N")) %>%
  # dplyr::select(-fox_p) %>%
  mutate_at(vars(hum_b, veh_b, dog_b, don_b, dof_b, pbd_b, gul_b, hof_b),
            ~ as.factor(.)) %>% 
  mutate_at(vars(hum_p, veh_p, dog_p, hof_p, fox_p),
            ~ ifelse(is.na(.), 0, .)) 

# nest_data_with_threat_data %>% filter(fundays > 10) %>% dplyr::select(fundays) %>% arrange(desc(fundays))

# nest_data_with_threat_data %>% 
#   filter()

# nest_data_with_threat_data %>% 
#   # filter(fundays <= 25) %>% 
#   ggplot() +
#   geom_histogram(aes(fundays)) +
#   # geom_vline(xintercept = log(10), color = "red") +
#   luke_theme

nest_data_with_threat_data %>% 
  ggplot() +
  geom_histogram(aes(halfway/n_surveys), binwidth = 1) +
  geom_vline(xintercept = 7, color = "red") +
  luke_theme

Code
nest_data_with_threat_data_7d <- 
  nest_data_with_threat_data %>% 
  filter(halfway/n_surveys <= 7) %>% 
  filter(fundays < 100)

# nest_data_with_threat_data

#### check variable distributions and collinearity ----
# determine the 99% quantile limit for each threat (i.e., to remove outlier data)
threat_data_99_ql_ <- 
  nest_data_with_threat_data_7d %>% 
  summarise_at(c("hum_a", "pbd_a", "gul_a", "veh_a", "dog_a", "don_a", "dof_a", 
                 "hum_m", "pbd_m", "gul_m", "veh_m", "dog_m", "don_m", "dof_m",
                 "hum_p", "veh_p", "dog_p", "hof_p", "fox_p"), 
               ~ quantile(.x, probs = c(0.99)))

nest_data_with_threat_data_7d %>% 
  filter(hum_a <= ceiling(as.numeric(threat_data_99_ql_$hum_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_a), binwidth = 5) +
  luke_theme +
  xlab("average number of humans counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(veh_a <= ceiling(as.numeric(threat_data_99_ql_$veh_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_a), binwidth = 1) +
  luke_theme +
  xlab("average number of vehicles counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dog_a <= ceiling(as.numeric(threat_data_99_ql_$dog_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(don_a <= ceiling(as.numeric(threat_data_99_ql_$don_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(don_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs on leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$dof_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dof_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs off leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(pbd_a), binwidth = 1) +
  luke_theme +
  xlab("average number of corvids counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$gul_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(gul_a), binwidth = 1) +
  luke_theme +
  xlab("average number of gulls counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(hum_m <= ceiling(as.numeric(threat_data_99_ql_$hum_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of humans counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(veh_m <= ceiling(as.numeric(threat_data_99_ql_$veh_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of vehicles counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dog_m <= ceiling(as.numeric(threat_data_99_ql_$dog_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(don_m <= ceiling(as.numeric(threat_data_99_ql_$don_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(don_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs on leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_m <= ceiling(as.numeric(threat_data_99_ql_$dof_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dof_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs off leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(pbd_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of corvids counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$gul_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(gul_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of gulls counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(hum_p <= ceiling(as.numeric(threat_data_99_ql_$hum_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_p), binwidth = 1) +
  luke_theme +
  xlab("maximum human print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(veh_p < ceiling(as.numeric(threat_data_99_ql_$veh_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_p), binwidth = 1) +
  luke_theme +
  xlab("maximum vehicle print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dog_p <= ceiling(as.numeric(threat_data_99_ql_$dog_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_p), binwidth = 1) +
  luke_theme +
  xlab("maximum dog print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(hof_p <= ceiling(as.numeric(threat_data_99_ql_$hof_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hof_p), binwidth = 1) +
  luke_theme +
  xlab("maximum hooved print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(fox_p <= ceiling(as.numeric(threat_data_99_ql_$fox_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(fox_p), binwidth = 1) +
  luke_theme +
  xlab("maximum fox print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d_ <- 
  nest_data_with_threat_data_7d %>% 
  filter(fox_p <= ceiling(as.numeric(threat_data_99_ql_$fox_p[1]))) %>% 
  filter(hum_a <= ceiling(as.numeric(threat_data_99_ql_$hum_a[1]))) %>% 
  filter(veh_a <= ceiling(as.numeric(threat_data_99_ql_$veh_a[1]))) %>% 
  filter(dog_a <= ceiling(as.numeric(threat_data_99_ql_$dog_a[1]))) %>% 
  filter(don_a <= ceiling(as.numeric(threat_data_99_ql_$don_a[1]))) %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$dof_a[1]))) %>% 
  filter(pbd_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_a[1]))) %>% 
  filter(gul_a <= ceiling(as.numeric(threat_data_99_ql_$gul_a[1]))) %>% 
  filter(hum_m <= ceiling(as.numeric(threat_data_99_ql_$hum_m[1]))) %>% 
  filter(veh_m <= ceiling(as.numeric(threat_data_99_ql_$veh_m[1]))) %>% 
  filter(dog_m <= ceiling(as.numeric(threat_data_99_ql_$dog_m[1]))) %>% 
  filter(don_m <= ceiling(as.numeric(threat_data_99_ql_$don_m[1]))) %>% 
  filter(dof_m <= ceiling(as.numeric(threat_data_99_ql_$dof_m[1]))) %>%
  filter(pbd_m <= ceiling(as.numeric(threat_data_99_ql_$pbd_m[1]))) %>% 
  filter(gul_m <= ceiling(as.numeric(threat_data_99_ql_$gul_m[1]))) %>% 
  filter(hum_p <= ceiling(as.numeric(threat_data_99_ql_$hum_p[1]))) %>% 
  filter(veh_p <= ceiling(as.numeric(threat_data_99_ql_$veh_p[1]))) %>% 
  filter(dog_p <= ceiling(as.numeric(threat_data_99_ql_$dog_p[1]))) %>% 
  filter(hof_p <= ceiling(as.numeric(threat_data_99_ql_$hof_p[1]))) %>%
  mutate(fox_p = ifelse(is.infinite(fox_p), 0, fox_p) %>% as.factor())

Nest survival modeling

Prepare data for RMark

Code
occ_FP <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "FP") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)

occ_MP <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "MP") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)

occ_BSC <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "BSC") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)

# create processed RMARK data format as NestSurvival with Year as group
nest_data.processed_FP_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "FP"), 
                      model = "Nest",
                      nocc = occ_FP, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site", 
                                                "level",
                                                "fox_p"))

nest_data.processed_MP_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "MP"), 
                      model = "Nest",
                      nocc = occ_MP, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site", 
                                                "level",
                                                "fox_p"))

nest_data.processed_BSC_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "BSC"), 
                      model = "Nest",
                      nocc = occ_BSC, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site", 
                                                "level",
                                                "fox_p"))

# create the design data
nest_fate.ddl_FP_5d <- RMark::make.design.data(nest_data.processed_FP_5d)
nest_fate.ddl_MP_5d <- RMark::make.design.data(nest_data.processed_MP_5d)
nest_fate.ddl_BSC_5d <- RMark::make.design.data(nest_data.processed_BSC_5d)

# add a new variable to the design data that is the quadratic transformation of
# time
time <- c(0:(occ_FP-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_FP)
nest_fate.ddl_FP_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_FP_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)

time <- c(0:(occ_MP-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_MP)
nest_fate.ddl_MP_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_MP_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)

time <- c(0:(occ_BSC-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_BSC)
nest_fate.ddl_BSC_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_BSC_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)

# nest_fate.ddl$S <- 
#   RMark::merge_design.covariates(nest_fate.ddl$S, data.frame(management_level = c(0, 1, 2, 3, 4)), 
#                                  bygroup = FALSE, bytime = FALSE)

# nest_fate.ddl$S <-
#   inner_join(nest_fate.ddl$S, int_threat_data, by = c("site", "time"))


RMark_data_FP <- 
  list(nest_data.processed = nest_data.processed_FP_5d, 
       nest_fate.ddl = nest_fate.ddl_FP_5d)

RMark_data_MP <- 
  list(nest_data.processed = nest_data.processed_MP_5d, 
       nest_fate.ddl = nest_fate.ddl_MP_5d)

RMark_data_BSC <- 
  list(nest_data.processed = nest_data.processed_BSC_5d, 
       nest_fate.ddl = nest_fate.ddl_BSC_5d)

# RMark_data_FP$nest_data.processed$data %>% summary()
# RMark_data_MP$nest_data.processed$data %>% summary()
# RMark_data_BSC$nest_data.processed$data %>% summary()
Code
### Fleurieu Peninsula model selection
nest_survival_FP <- function()
{
  # Specify models to test
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # Linear trend in DSR
  S.Time <-
    list(formula = ~Time)

  # Quadratic trend in DSR
  S.Quadratic_Time <-
    list(formula = ~Time + Quadratic)

  # Cubic trend in DSR
  S.Cubic_Time <-
    list(formula = ~Time + Quadratic + Cubic)
  
  # Linear trend of weekends and holidays on DSR
  S.fundays <-
    list(formula = ~fundays)
  
  # weekends and holidays and management levels
  S.fundays_level <-
    list(formula = ~fundays + level)
  
  #### average counts
  # average humans detected
  S.hum_a <-
    list(formula = ~hum_a)
  
  # average vehicles detected
  S.veh_a <-
    list(formula = ~veh_a)
  
  # average dogs detected
  S.dog_a <-
    list(formula = ~dog_a)
  
  # average dogs off leash detected
  S.dof_a <-
    list(formula = ~dof_a)
  
  # average hoofed animals detected
  S.hof_a <-
    list(formula = ~hof_a)
  
  # average corvids detected
  S.pbd_a <-
    list(formula = ~pbd_a)
  
  # average gulls detected
  S.gul_a <-
    list(formula = ~gul_a)
  
  # fox print levels
  S.fox_p <-
    list(formula = ~fox_p)
  
  #### maximum counts
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  S.veh_m <-
    list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction with management levels
  # average humans detected and management levels
  S.hum_a_level <-
    list(formula = ~hum_a + level)
  
  # average vehicles detected and management levels
  S.veh_a_level <-
    list(formula = ~veh_a + level)
  
  # average dogs detected and management levels
  S.dog_a_level <-
    list(formula = ~dog_a + level)
  
  # average dogs off leash detected and management levels
  S.dof_a_level <-
    list(formula = ~dof_a + level)
  
  # average corvids detected and management levels
  S.pbd_a_level <-
    list(formula = ~pbd_a + level)
  
  # average gulls detected and management levels
  S.gul_a_level <-
    list(formula = ~gul_a + level)
  
  #### interaction with management levels and management levels
  # max humans detected
  S.hum_m_level <-
    list(formula = ~hum_m + level)
  
  # max vehicles detected and management levels
  S.veh_m_level <-
    list(formula = ~veh_m + level)
  
  # max dogs detected and management levels
  S.dog_m_level <-
    list(formula = ~dog_m + level)
  
  # max dogs off leash detected and management levels
  S.dof_m_level <-
    list(formula = ~dof_m + level)
  
  # max corvids detected and management levels
  S.pbd_m_level <-
    list(formula = ~pbd_m + level)
  
  # max gulls detected and management levels
  S.gul_m_level <-
    list(formula = ~gul_m + level)
  
  # between-year variation in DSR
  S.season <-
    list(formula = ~season)

  # Cubic trend and annual variation DSR among years
  S.Cubic_Time_season <-
    list(formula = ~Time + Quadratic + Cubic + season)

  # habitat-specific variation in DSR
  S.habitat <-
    list(formula = ~nest_hab)

  # Cubic trend habitat-specific variation in DSR
  S.Cubic_Time_habitat <-
    list(formula = ~Time + Quadratic + Cubic + nest_hab)
  
  # Cubic trend and interaction between habitat and management levels on DSR
  S.Cubic_Time_level_habitat <-
    list(formula = ~Time + Quadratic + Cubic + level + nest_hab)
  
  # habitat and management on DSR
  S.status_habitat <-
    list(formula = ~level + nest_hab)

  # managsment-specific variation in DSR
  S.level<-
    list(formula = ~level)

  # Cubic trend management-specific variation in DSR
  S.Cubic_Time_level <-
    list(formula = ~Time + Quadratic + Cubic + level)

  # Cubic trend management-specific variation in DSR and max humans
  S.Cubic_Time_level_hum_m <-
    list(formula = ~Time + Quadratic + Cubic + level + hum_m)
  
  # Cubic trend management-specific variation in DSR and mean humans
  S.Cubic_Time_level_hum_a <-
    list(formula = ~Time + Quadratic + Cubic + level + hum_a)
  
  # Cubic trend in DSR and max humans
  S.Cubic_Time_hum_m <-
    list(formula = ~Time + Quadratic + Cubic + hum_m)
  
  # Cubic trend in DSR and mean humans
  S.Cubic_Time_hum_a <-
    list(formula = ~Time + Quadratic + Cubic + hum_a)
  
  # Cubic trend in DSR and max dogs
  S.Cubic_Time_dog_m <-
    list(formula = ~Time + Quadratic + Cubic + dog_m)
  
  # Cubic trend management-specific variation in DSR and avg dogs
  S.Cubic_Time_level_dog_a <-
    list(formula = ~Time + Quadratic + Cubic + level + dog_a)
  
  # Cubic trend management-specific variation in DSR and max dogs
  S.Cubic_Time_level_dog_m <-
    list(formula = ~Time + Quadratic + Cubic + level + dog_m)
  
  # Cubic trend in DSR and avg dogs
  S.Cubic_Time_dog_a <-
    list(formula = ~Time + Quadratic + Cubic + dog_a)
  
  # Cubic trend management-specific variation in DSR and max predatory birds
  S.Cubic_Time_level_pbd_m <-
    list(formula = ~Time + Quadratic + Cubic + level + pbd_m)
  
  # Cubic trend management-specific variation in DSR and avg pred birds
  S.Cubic_Time_level_pbd_a <-
    list(formula = ~Time + Quadratic + Cubic + level + pbd_a)
  
  # Cubic seasonal trend and max. pred. birds
  S.Cubic_Time_pbd_m <-
    list(formula = ~Time + Quadratic + Cubic + pbd_m)
  
  # Cubic seasonal trend and average pred. birds
  S.Cubic_Time_pbd_a <-
    list(formula = ~Time + Quadratic + Cubic + pbd_a)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_FP$nest_data.processed, 
                                    ddl = RMark_data_FP$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_FP <- nest_survival_FP()
nest_survival_run_FP
nest_survival_FP <- 
  list(RMark_data = RMark_data_FP, 
       model_selection = nest_survival_run_FP)
saveRDS(nest_survival_FP, file = "output/nest_survival_FP.rds")
Code
### Mornington Peninsula model selection
nest_survival_MP <- function()
{
  # Specify models to test
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # Linear trend in DSR
  S.Time <-
    list(formula = ~Time)

  # Quadratic trend in DSR
  S.Quadratic_Time <-
    list(formula = ~Time + Quadratic)

  # Cubic trend in DSR
  S.Cubic_Time <-
    list(formula = ~Time + Quadratic + Cubic)
  
  # Linear trend of weekends and holidays on DSR
  S.fundays <-
    list(formula = ~fundays)
  
  # weekends and holidays and management levels
  S.fundays_level <-
    list(formula = ~fundays + level)
  
  #### average counts
  # average humans detected
  S.hum_a <-
    list(formula = ~hum_a)
  
  # average vehicles detected
  S.veh_a <-
    list(formula = ~veh_a)
  
  # average dogs detected
  S.dog_a <-
    list(formula = ~dog_a)
  
  # average dogs off leash detected
  S.dof_a <-
    list(formula = ~dof_a)
  
  # average hoofed animals detected
  S.hof_a <-
    list(formula = ~hof_a)
  
  # average corvids detected
  S.pbd_a <-
    list(formula = ~pbd_a)
  
  # average gulls detected
  S.gul_a <-
    list(formula = ~gul_a)
  
  # fox print levels
  S.fox_p <-
    list(formula = ~fox_p)
  
  #### maximum counts
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  S.veh_m <-
    list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction with management levels
  # average humans detected and management levels
  S.hum_a_level <-
    list(formula = ~hum_a + level)
  
  # average vehicles detected and management levels
  S.veh_a_level <-
    list(formula = ~veh_a + level)
  
  # average dogs detected and management levels
  S.dog_a_level <-
    list(formula = ~dog_a + level)
  
  # average dogs off leash detected and management levels
  S.dof_a_level <-
    list(formula = ~dof_a + level)
  
  # average corvids detected and management levels
  S.pbd_a_level <-
    list(formula = ~pbd_a + level)
  
  # average gulls detected and management levels
  S.gul_a_level <-
    list(formula = ~gul_a + level)
  
  #### interaction with management levels and management levels
  # max humans detected
  S.hum_m_level <-
    list(formula = ~hum_m + level)
  
  # max vehicles detected and management levels
  S.veh_m_level <-
    list(formula = ~veh_m + level)
  
  # max dogs detected and management levels
  S.dog_m_level <-
    list(formula = ~dog_m + level)
  
  # max dogs off leash detected and management levels
  S.dof_m_level <-
    list(formula = ~dof_m + level)
  
  # max corvids detected and management levels
  S.pbd_m_level <-
    list(formula = ~pbd_m + level)
  
  # max gulls detected and management levels
  S.gul_m_level <-
    list(formula = ~gul_m + level)
  
  # between-year variation in DSR
  S.season <-
    list(formula = ~season)

  # Cubic trend and annual variation DSR among years
  S.Cubic_Time_season <-
    list(formula = ~Time + Quadratic + Cubic + season)

  # habitat-specific variation in DSR
  S.habitat <-
    list(formula = ~nest_hab)

  # Cubic trend habitat-specific variation in DSR
  S.Cubic_Time_habitat <-
    list(formula = ~Time + Quadratic + Cubic + nest_hab)
  
  # Cubic trend and interaction between habitat and management levels on DSR
  S.Cubic_Time_level_habitat <-
    list(formula = ~Time + Quadratic + Cubic + level + nest_hab)
  
  # habitat and management on DSR
  S.status_habitat <-
    list(formula = ~level + nest_hab)

  # managsment-specific variation in DSR
  S.level<-
    list(formula = ~level)

  # Cubic trend management-specific variation in DSR
  S.Cubic_Time_level <-
    list(formula = ~Time + Quadratic + Cubic + level)

  # Cubic trend management-specific variation in DSR and max humans
  S.Cubic_Time_level_hum_m <-
    list(formula = ~Time + Quadratic + Cubic + level + hum_m)
  
  # Cubic trend management-specific variation in DSR and mean humans
  S.Cubic_Time_level_hum_a <-
    list(formula = ~Time + Quadratic + Cubic + level + hum_a)
  
  # Cubic trend in DSR and max humans
  S.Cubic_Time_hum_m <-
    list(formula = ~Time + Quadratic + Cubic + hum_m)
  
  # Cubic trend in DSR and mean humans
  S.Cubic_Time_hum_a <-
    list(formula = ~Time + Quadratic + Cubic + hum_a)
  
  # Cubic trend in DSR and max dogs
  S.Cubic_Time_dog_m <-
    list(formula = ~Time + Quadratic + Cubic + dog_m)
  
  # Cubic trend management-specific variation in DSR and avg dogs
  S.Cubic_Time_level_dog_a <-
    list(formula = ~Time + Quadratic + Cubic + level + dog_a)
  
  # Cubic trend management-specific variation in DSR and max dogs
  S.Cubic_Time_level_dog_m <-
    list(formula = ~Time + Quadratic + Cubic + level + dog_m)
  
  # Cubic trend in DSR and avg dogs
  S.Cubic_Time_dog_a <-
    list(formula = ~Time + Quadratic + Cubic + dog_a)
  
  # Cubic trend management-specific variation in DSR and max predatory birds
  S.Cubic_Time_level_pbd_m <-
    list(formula = ~Time + Quadratic + Cubic + level + pbd_m)
  
  # Cubic trend management-specific variation in DSR and avg pred birds
  S.Cubic_Time_level_pbd_a <-
    list(formula = ~Time + Quadratic + Cubic + level + pbd_a)
  
  # Cubic seasonal trend and max. pred. birds
  S.Cubic_Time_pbd_m <-
    list(formula = ~Time + Quadratic + Cubic + pbd_m)
  
  # Cubic seasonal trend and average pred. birds
  S.Cubic_Time_pbd_a <-
    list(formula = ~Time + Quadratic + Cubic + pbd_a)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_MP$nest_data.processed, 
                                    ddl = RMark_data_MP$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_MP <- nest_survival_MP()
nest_survival_run_MP
nest_survival_MP <- 
  list(RMark_data = RMark_data_MP, 
       model_selection = nest_survival_run_MP)
saveRDS(nest_survival_MP, file = "output/nest_survival_MP.rds")
Code
### Bellarine / Surf Coast model selection
nest_survival_BSC <- function()
{
  # Specify models to test
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # Linear trend in DSR
  S.Time <-
    list(formula = ~Time)

  # Quadratic trend in DSR
  S.Quadratic_Time <-
    list(formula = ~Time + Quadratic)

  # Cubic trend in DSR
  S.Cubic_Time <-
    list(formula = ~Time + Quadratic + Cubic)
  
  # Linear trend of weekends and holidays on DSR
  S.fundays <-
    list(formula = ~fundays)
  
  # weekends and holidays and management levels
  S.fundays_level <-
    list(formula = ~fundays + level)
  
  #### average counts
  # average humans detected
  S.hum_a <-
    list(formula = ~hum_a)
  
  # average vehicles detected
  S.veh_a <-
    list(formula = ~veh_a)
  
  # average dogs detected
  S.dog_a <-
    list(formula = ~dog_a)
  
  # average dogs off leash detected
  S.dof_a <-
    list(formula = ~dof_a)
  
  # average hoofed animals detected
  S.hof_a <-
    list(formula = ~hof_a)
  
  # average corvids detected
  S.pbd_a <-
    list(formula = ~pbd_a)
  
  # average gulls detected
  S.gul_a <-
    list(formula = ~gul_a)
  
  # fox print levels
  S.fox_p <-
    list(formula = ~fox_p)
  
  #### maximum counts
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  S.veh_m <-
    list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction with management levels
  # average humans detected and management levels
  S.hum_a_level <-
    list(formula = ~hum_a + level)
  
  # average vehicles detected and management levels
  S.veh_a_level <-
    list(formula = ~veh_a + level)
  
  # average dogs detected and management levels
  S.dog_a_level <-
    list(formula = ~dog_a + level)
  
  # average dogs off leash detected and management levels
  S.dof_a_level <-
    list(formula = ~dof_a + level)
  
  # average corvids detected and management levels
  S.pbd_a_level <-
    list(formula = ~pbd_a + level)
  
  # average gulls detected and management levels
  S.gul_a_level <-
    list(formula = ~gul_a + level)
  
  #### interaction with management levels and management levels
  # max humans detected
  S.hum_m_level <-
    list(formula = ~hum_m + level)
  
  # max vehicles detected and management levels
  S.veh_m_level <-
    list(formula = ~veh_m + level)
  
  # max dogs detected and management levels
  S.dog_m_level <-
    list(formula = ~dog_m + level)
  
  # max dogs off leash detected and management levels
  S.dof_m_level <-
    list(formula = ~dof_m + level)
  
  # max corvids detected and management levels
  S.pbd_m_level <-
    list(formula = ~pbd_m + level)
  
  # max gulls detected and management levels
  S.gul_m_level <-
    list(formula = ~gul_m + level)
  
  # between-year variation in DSR
  S.season <-
    list(formula = ~season)

  # Cubic trend and annual variation DSR among years
  S.Cubic_Time_season <-
    list(formula = ~Time + Quadratic + Cubic + season)

  # habitat-specific variation in DSR
  S.habitat <-
    list(formula = ~nest_hab)

  # Cubic trend habitat-specific variation in DSR
  S.Cubic_Time_habitat <-
    list(formula = ~Time + Quadratic + Cubic + nest_hab)
  
  # Cubic trend and interaction between habitat and management levels on DSR
  S.Cubic_Time_level_habitat <-
    list(formula = ~Time + Quadratic + Cubic + level + nest_hab)
  
  # habitat and management on DSR
  S.status_habitat <-
    list(formula = ~level + nest_hab)

  # managsment-specific variation in DSR
  S.level<-
    list(formula = ~level)

  # Cubic trend management-specific variation in DSR
  S.Cubic_Time_level <-
    list(formula = ~Time + Quadratic + Cubic + level)

  # Cubic trend management-specific variation in DSR and max humans
  S.Cubic_Time_level_hum_m <-
    list(formula = ~Time + Quadratic + Cubic + level + hum_m)
  
  # Cubic trend management-specific variation in DSR and mean humans
  S.Cubic_Time_level_hum_a <-
    list(formula = ~Time + Quadratic + Cubic + level + hum_a)
  
  # Cubic trend in DSR and max humans
  S.Cubic_Time_hum_m <-
    list(formula = ~Time + Quadratic + Cubic + hum_m)
  
  # Cubic trend in DSR and mean humans
  S.Cubic_Time_hum_a <-
    list(formula = ~Time + Quadratic + Cubic + hum_a)
  
  # Cubic trend in DSR and max dogs
  S.Cubic_Time_dog_m <-
    list(formula = ~Time + Quadratic + Cubic + dog_m)
  
  # Cubic trend management-specific variation in DSR and avg dogs
  S.Cubic_Time_level_dog_a <-
    list(formula = ~Time + Quadratic + Cubic + level + dog_a)
  
  # Cubic trend management-specific variation in DSR and max dogs
  S.Cubic_Time_level_dog_m <-
    list(formula = ~Time + Quadratic + Cubic + level + dog_m)
  
  # Cubic trend in DSR and avg dogs
  S.Cubic_Time_dog_a <-
    list(formula = ~Time + Quadratic + Cubic + dog_a)
  
  # Cubic trend management-specific variation in DSR and max predatory birds
  S.Cubic_Time_level_pbd_m <-
    list(formula = ~Time + Quadratic + Cubic + level + pbd_m)
  
  # Cubic trend management-specific variation in DSR and avg pred birds
  S.Cubic_Time_level_pbd_a <-
    list(formula = ~Time + Quadratic + Cubic + level + pbd_a)
  
  # Cubic seasonal trend and max. pred. birds
  S.Cubic_Time_pbd_m <-
    list(formula = ~Time + Quadratic + Cubic + pbd_m)
  
  # Cubic seasonal trend and average pred. birds
  S.Cubic_Time_pbd_a <-
    list(formula = ~Time + Quadratic + Cubic + pbd_a)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_BSC$nest_data.processed, 
                                    ddl = RMark_data_BSC$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_BSC <- nest_survival_BSC()
nest_survival_run_BSC
nest_survival_BSC <- 
  list(RMark_data = RMark_data_BSC, 
       model_selection = nest_survival_run_BSC)
saveRDS(nest_survival_BSC, file = "output/nest_survival_BSC.rds")

Results

Only the top 10 models are shown here in each table for simplicity

Code
nest_survival_FP <- readRDS(file = "output/nest_survival_FP.rds")
nest_survival_run_FP <- nest_survival_FP$model_selection

nest_survival_run_FP$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  slice(1:10) %>% 
  # gt(rowname_col = "row",
  #    groupname_col = "effect") %>% 
  gt() %>% 
  cols_label(model = html("<i>Fleurieu Peninsula</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(60))
Fleurieu Peninsula K DeltaAICc weight
S(~fundays + level) 6 0.00 0.990
S(~fundays) 2 9.27 0.010
S(~pbd_m + level) 6 63.76 0.000
S(~hum_a + level) 6 65.30 0.000
S(~dog_a + level) 6 65.98 0.000
S(~gul_m + level) 6 67.24 0.000
S(~Time + Quadratic + Cubic + level + pbd_m) 9 67.42 0.000
S(~veh_a + level) 6 67.84 0.000
S(~level) 5 68.19 0.000
S(~dof_m + level) 6 68.24 0.000
Code
nest_survival_MP <- readRDS(file = "output/nest_survival_MP.rds")
nest_survival_run_MP <- nest_survival_MP$model_selection

nest_survival_run_MP$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  slice(1:10) %>% 
  # gt(rowname_col = "row",
  #    groupname_col = "effect") %>% 
  gt() %>% 
  cols_label(model = html("<i>Mornington Peninsula</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(60))
Mornington Peninsula K DeltaAICc weight
S(~fundays) 2 0.00 0.975
S(~fundays + level) 6 7.33 0.025
S(~fox_p) 4 109.83 0.000
S(~pbd_m) 2 124.59 0.000
S(~pbd_m + level) 6 125.03 0.000
S(~Time + Quadratic + Cubic + level + pbd_m) 9 127.56 0.000
S(~Time + Quadratic + Cubic + pbd_m) 5 127.58 0.000
S(~nest_hab) 4 132.21 0.000
S(~gul_m) 2 132.23 0.000
S(~1) 1 132.61 0.000
Code
nest_survival_BSC <- readRDS(file = "output/nest_survival_BSC.rds")
nest_survival_run_BSC <- nest_survival_BSC$model_selection

nest_survival_run_BSC$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  slice(1:10) %>% 
  # gt(rowname_col = "row",
  #    groupname_col = "effect") %>% 
  gt() %>% 
  cols_label(model = html("<i>Bellarine / Surf Coast</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(60))
Bellarine / Surf Coast K DeltaAICc weight
S(~fundays + level) 6 0.00 0.998
S(~veh_a + level) 6 15.69 0.000
S(~veh_m + level) 6 15.69 0.000
S(~Time + Quadratic + Cubic + level + nest_hab) 10 16.06 0.000
S(~level + nest_hab) 7 17.91 0.000
S(~pbd_m + level) 6 17.94 0.000
S(~Time + Quadratic + Cubic + level + pbd_m) 9 18.49 0.000
S(~gul_a + level) 6 18.61 0.000
S(~level) 5 19.16 0.000
S(~hum_a + level) 6 19.34 0.000

Effect of weekends and holidays on nest survival

Code
S.fundays <- nest_survival_run_FP[[28]]
# S.fundays$results$beta
min.fundays = min(RMark_data_FP$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_FP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_FP <- 
  pred.fundays$estimates %>% 
  mutate(region = "FP")

S.fundays <- nest_survival_run_MP[[28]]
# S.fundays$results$beta
min.fundays = min(RMark_data_MP$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_MP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)

pred.fundays_MP <- 
  pred.fundays$estimates %>% 
  mutate(region = "MP")

S.fundays <- nest_survival_run_BSC[[28]]
# S.fundays$results$beta
min.fundays = min(RMark_data_BSC$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_BSC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)

pred.fundays_BSC <- 
  pred.fundays$estimates %>% 
  mutate(region = "BSC")

pred.fundays <- 
  bind_rows(pred.fundays_FP, pred.fundays_MP, pred.fundays_BSC)

ggplot(pred.fundays, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("number of weekend days and holidays exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of management Levels on nest survival

Code
nest_survival_reals_FP_levels <- 
  nest_survival_run_FP[[40]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_levels), " ", n = 4))
nest_survival_reals_FP_levels <- cbind(Groups, nest_survival_reals_FP_levels)
nest_survival_reals_FP_levels$rows <-  rownames(nest_survival_reals_FP_levels)
nest_survival_reals_FP_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_FP_levels$rows, 
                    nchar(nest_survival_reals_FP_levels$rows) - 8, nchar(nest_survival_reals_FP_levels$rows) - 7))
nest_survival_reals_FP_levels <- 
  nest_survival_reals_FP_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_levels) <- NULL

nest_survival_reals_MP_levels <- 
  nest_survival_run_MP[[40]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_levels), " ", n = 4))
nest_survival_reals_MP_levels <- cbind(Groups, nest_survival_reals_MP_levels)
nest_survival_reals_MP_levels$rows <-  rownames(nest_survival_reals_MP_levels)
nest_survival_reals_MP_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_MP_levels$rows, 
                    nchar(nest_survival_reals_MP_levels$rows) - 8, nchar(nest_survival_reals_MP_levels$rows) - 7))
nest_survival_reals_MP_levels <- 
  nest_survival_reals_MP_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_levels) <- NULL

nest_survival_reals_BSC_levels <- 
  nest_survival_run_BSC[[40]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_levels), " ", n = 4))
nest_survival_reals_BSC_levels <- cbind(Groups, nest_survival_reals_BSC_levels)
nest_survival_reals_BSC_levels$rows <-  rownames(nest_survival_reals_BSC_levels)
nest_survival_reals_BSC_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_BSC_levels$rows, 
                    nchar(nest_survival_reals_BSC_levels$rows) - 8, nchar(nest_survival_reals_BSC_levels$rows) - 7))
nest_survival_reals_BSC_levels <- 
  nest_survival_reals_BSC_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_levels) <- NULL

nest_survival_reals_levels <- 
  bind_rows(nest_survival_reals_FP_levels, 
            nest_survival_reals_MP_levels, 
            nest_survival_reals_BSC_levels)

ggplot() +
  geom_line(data = nest_survival_reals_levels, 
            aes(x = management_level, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2) +
  geom_errorbar(data = nest_survival_reals_levels, 
                aes(ymin = lcl, ymax = ucl, 
                    x = management_level, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_levels, 
             aes(x = management_level, y = estimate, fill = region),
             shape = 21, size = 2, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.8, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("management level") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.4, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula"))

Effect of Habitat on nest survival

Code
nest_survival_reals_FP_habitat <- 
  nest_survival_run_FP[[34]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_habitat), " ", n = 4))
nest_survival_reals_FP_habitat <- cbind(Groups, nest_survival_reals_FP_habitat)
nest_survival_reals_FP_habitat$habitat <- str_extract(nest_survival_reals_FP_habitat$X2, c("Beach", "Dune", "Foredune/face"))
nest_survival_reals_FP_habitat <- 
  nest_survival_reals_FP_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_habitat) <- NULL

nest_survival_reals_MP_habitat <- 
  nest_survival_run_MP[[34]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_habitat), " ", n = 4))
nest_survival_reals_MP_habitat <- cbind(Groups, nest_survival_reals_MP_habitat)
nest_survival_reals_MP_habitat$habitat <- str_extract(nest_survival_reals_MP_habitat$X2, c("Beach", "Dune", "Foredune/face", "Rocks"))
nest_survival_reals_MP_habitat <- 
  nest_survival_reals_MP_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_habitat) <- NULL

nest_survival_reals_BSC_habitat <- 
  nest_survival_run_BSC[[34]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_habitat), " ", n = 4))
nest_survival_reals_BSC_habitat <- cbind(Groups, nest_survival_reals_BSC_habitat)
nest_survival_reals_BSC_habitat$habitat <- str_extract(nest_survival_reals_BSC_habitat$X2, c("Beach", "Dune", "Foredune/face"))
nest_survival_reals_BSC_habitat <- 
  nest_survival_reals_BSC_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_habitat) <- NULL

nest_survival_reals_habitat <- 
  bind_rows(nest_survival_reals_FP_habitat, 
            nest_survival_reals_MP_habitat, 
            nest_survival_reals_BSC_habitat)

ggplot() +
  geom_errorbar(data = nest_survival_reals_habitat, 
                aes(ymin = lcl, ymax = ucl, 
                    x = habitat, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_habitat, 
             aes(x = habitat, y = estimate, fill = region),
             shape = 21, size = 2, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.5, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("habitat") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.75, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula"))

Effect of dogs on nest survival (max counted)

Code
S.dog_m <- nest_survival_run_FP[[24]]
# S.dog_m$results$beta
min.dog_m = min(RMark_data_FP$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_FP$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = 1)
pred.dog_m_FP <- 
  pred.dog_m$estimates %>% 
  mutate(region = "FP")

S.dog_m <- nest_survival_run_MP[[24]]
# S.dog_m$results$beta
min.dog_m = min(RMark_data_MP$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_MP$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = 1)

pred.dog_m_MP <- 
  pred.dog_m$estimates %>% 
  mutate(region = "MP")

S.dog_m <- nest_survival_run_BSC[[24]]
# S.dog_m$results$beta
min.dog_m = min(RMark_data_BSC$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_BSC$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = 1)

pred.dog_m_BSC <- 
  pred.dog_m$estimates %>% 
  mutate(region = "BSC")

pred.dog_m <- 
  bind_rows(pred.dog_m_FP, pred.dog_m_MP, pred.dog_m_BSC)

ggplot(pred.dog_m, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of dogs exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of Dogs off leash on nest survival (max counted)

Code
S.dof_m <- nest_survival_run_FP[[20]]
# S.dof_m$results$beta
min.dof_m = min(RMark_data_FP$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_FP$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = 1)
pred.dof_m_FP <- 
  pred.dof_m$estimates %>% 
  mutate(region = "FP")

S.dof_m <- nest_survival_run_MP[[19]]
# S.dof_m$results$beta
min.dof_m = min(RMark_data_MP$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_MP$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = 1)

pred.dof_m_MP <- 
  pred.dof_m$estimates %>% 
  mutate(region = "MP")

S.dof_m <- nest_survival_run_BSC[[20]]
# S.dof_m$results$beta
min.dof_m = min(RMark_data_BSC$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_BSC$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = 1)

pred.dof_m_BSC <- 
  pred.dof_m$estimates %>% 
  mutate(region = "BSC")

pred.dof_m <- 
  bind_rows(pred.dof_m_FP, pred.dof_m_MP, pred.dof_m_BSC)

ggplot(pred.dof_m, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of dogs off leash exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of humans on nest survival (max counted)

Code
S.hum_m <- nest_survival_run_FP[[38]]
# S.hum_m$results$beta
min.hum_m = min(RMark_data_FP$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_FP$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = 1)
pred.hum_m_FP <- 
  pred.hum_m$estimates %>% 
  mutate(region = "FP")

S.hum_m <- nest_survival_run_MP[[38]]
# S.hum_m$results$beta
min.hum_m = min(RMark_data_MP$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_MP$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = 1)

pred.hum_m_MP <- 
  pred.hum_m$estimates %>% 
  mutate(region = "MP")

S.hum_m <- nest_survival_run_BSC[[38]]
# S.hum_m$results$beta
min.hum_m = min(RMark_data_BSC$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_BSC$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = 1)

pred.hum_m_BSC <- 
  pred.hum_m$estimates %>% 
  mutate(region = "BSC")

pred.hum_m <- 
  bind_rows(pred.hum_m_FP, pred.hum_m_MP, pred.hum_m_BSC)

ggplot(pred.hum_m, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 10, 20, 30, 40)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of humans exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of corvids on nest survival (max counted)

Code
S.pbd_m <- nest_survival_run_FP[[43]]
# S.pbd_m$results$beta
min.pbd_m = min(RMark_data_FP$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_FP$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = 1)
pred.pbd_m_FP <- 
  pred.pbd_m$estimates %>% 
  mutate(region = "FP")

S.pbd_m <- nest_survival_run_MP[[43]]
# S.pbd_m$results$beta
min.pbd_m = min(RMark_data_MP$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_MP$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = 1)

pred.pbd_m_MP <- 
  pred.pbd_m$estimates %>% 
  mutate(region = "MP")

S.pbd_m <- nest_survival_run_BSC[[43]]
# S.pbd_m$results$beta
min.pbd_m = min(RMark_data_BSC$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_BSC$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = 1)

pred.pbd_m_BSC <- 
  pred.pbd_m$estimates %>% 
  mutate(region = "BSC")

pred.pbd_m <- 
  bind_rows(pred.pbd_m_FP, pred.pbd_m_MP, pred.pbd_m_BSC)

ggplot(pred.pbd_m, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 10, 20, 30)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of ravens and magpies exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of gulls on nest survival (max counted)

Code
S.gul_m <- nest_survival_run_FP[[32]]
# S.gul_m$results$beta
min.gul_m = min(RMark_data_FP$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_FP$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = 1)
pred.gul_m_FP <- 
  pred.gul_m$estimates %>% 
  mutate(region = "FP")

S.gul_m <- nest_survival_run_MP[[32]]
# S.gul_m$results$beta
min.gul_m = min(RMark_data_MP$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_MP$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = 1)

pred.gul_m_MP <- 
  pred.gul_m$estimates %>% 
  mutate(region = "MP")

S.gul_m <- nest_survival_run_BSC[[32]]
# S.gul_m$results$beta
min.gul_m = min(RMark_data_BSC$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_BSC$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = 1)

pred.gul_m_BSC <- 
  pred.gul_m$estimates %>% 
  mutate(region = "BSC")

pred.gul_m <- 
  bind_rows(pred.gul_m_FP, pred.gul_m_MP, pred.gul_m_BSC)

ggplot(pred.gul_m, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 50, 100, 150, 200)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of ravens and magpies exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of Fox activity on nest survival (max print level)

Code
nest_survival_reals_FP_fox_p <- 
  nest_survival_run_FP[[27]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_fox_p), " ", n = 4))
nest_survival_reals_FP_fox_p <- cbind(Groups, nest_survival_reals_FP_fox_p)
nest_survival_reals_FP_fox_p$rows <-  rownames(nest_survival_reals_FP_fox_p)
nest_survival_reals_FP_fox_p$fox_p <- 
  str_sub(nest_survival_reals_FP_fox_p$rows, 
          nchar(nest_survival_reals_FP_fox_p$rows) - 6, 
          nchar(nest_survival_reals_FP_fox_p$rows) - 6)
nest_survival_reals_FP_fox_p$fox_p <- 
  as.factor(nest_survival_reals_FP_fox_p$fox_p)
nest_survival_reals_FP_fox_p <- 
  nest_survival_reals_FP_fox_p %>% 
  dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP") %>% 
  slice(-1)
row.names(nest_survival_reals_FP_fox_p) <- NULL

nest_survival_reals_MP_fox_p <- 
  nest_survival_run_MP[[27]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_fox_p), " ", n = 4))
nest_survival_reals_MP_fox_p <- cbind(Groups, nest_survival_reals_MP_fox_p)
nest_survival_reals_MP_fox_p$rows <-  rownames(nest_survival_reals_MP_fox_p)
nest_survival_reals_MP_fox_p$fox_p <- 
  str_sub(nest_survival_reals_MP_fox_p$rows, 
          nchar(nest_survival_reals_MP_fox_p$rows) - 6, 
          nchar(nest_survival_reals_MP_fox_p$rows) - 6)
nest_survival_reals_MP_fox_p$fox_p <- 
  as.factor(nest_survival_reals_MP_fox_p$fox_p)
nest_survival_reals_MP_fox_p <- 
  nest_survival_reals_MP_fox_p %>% 
  dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP") %>% 
  slice(-1)
row.names(nest_survival_reals_MP_fox_p) <- NULL

nest_survival_reals_BSC_fox_p <- 
  nest_survival_run_BSC[[27]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_fox_p), " ", n = 4))
nest_survival_reals_BSC_fox_p <- cbind(Groups, nest_survival_reals_BSC_fox_p)
nest_survival_reals_BSC_fox_p$rows <-  rownames(nest_survival_reals_BSC_fox_p)
nest_survival_reals_BSC_fox_p$fox_p <- 
  str_sub(nest_survival_reals_BSC_fox_p$rows, 
          nchar(nest_survival_reals_BSC_fox_p$rows) - 6, 
          nchar(nest_survival_reals_BSC_fox_p$rows) - 6) %>% as.factor()
nest_survival_reals_BSC_fox_p <- 
  nest_survival_reals_BSC_fox_p %>% 
  dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC") %>% 
  slice(-1)
row.names(nest_survival_reals_BSC_fox_p) <- NULL

nest_survival_reals_levels <- 
  bind_rows(nest_survival_reals_FP_fox_p, 
            nest_survival_reals_MP_fox_p, 
            nest_survival_reals_BSC_fox_p)

ggplot() +
  geom_line(data = nest_survival_reals_levels, 
            aes(x = fox_p, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2) +
  geom_errorbar(data = nest_survival_reals_levels, 
                aes(ymin = lcl, ymax = ucl, 
                    x = fox_p, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_levels, 
             aes(x = fox_p, y = estimate, fill = region),
             shape = 21, size = 2, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.9, 0.1),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("fox prints") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.55, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula"))

Effect of vehicles on nest survival (max)

Code
S.veh_m <- nest_survival_run_FP[[51]]
# S.veh_m$results$beta
min.veh_m = min(RMark_data_FP$nest_data.processed$data$veh_m)
max.veh_m = max(RMark_data_FP$nest_data.processed$data$veh_m)
veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
pred.veh_m <- 
  covariate.predictions(model = S.veh_m, 
                        data = data.frame(veh_m = veh_m.values),
                        indices = 1)
pred.veh_m_FP <- 
  pred.veh_m$estimates %>% 
  mutate(region = "FP")

S.veh_m <- nest_survival_run_MP[[51]]
# S.veh_m$results$beta
min.veh_m = min(RMark_data_MP$nest_data.processed$data$veh_m)
max.veh_m = max(RMark_data_MP$nest_data.processed$data$veh_m)
veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
pred.veh_m <- 
  covariate.predictions(model = S.veh_m, 
                        data = data.frame(veh_m = veh_m.values),
                        indices = 1)

pred.veh_m_MP <- 
  pred.veh_m$estimates %>% 
  mutate(region = "MP")

S.veh_m <- nest_survival_run_BSC[[51]]
# S.veh_m$results$beta
min.veh_m = min(RMark_data_BSC$nest_data.processed$data$veh_m)
max.veh_m = max(RMark_data_BSC$nest_data.processed$data$veh_m)
veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
pred.veh_m <- 
  covariate.predictions(model = S.veh_m, 
                        data = data.frame(veh_m = veh_m.values),
                        indices = 1)

pred.veh_m_BSC <- 
  pred.veh_m$estimates %>% 
  mutate(region = "BSC")

pred.veh_m <- 
  bind_rows(pred.veh_m_FP, pred.veh_m_MP, pred.veh_m_BSC)

ggplot(pred.veh_m, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 1, 2, 3)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of vehicles exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Annual variation in nest survival

Code
nest_survival_reals_FP_season <- 
  nest_survival_run_FP[[46]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_season), " ", n = 4))
nest_survival_reals_FP_season <- cbind(Groups, nest_survival_reals_FP_season)
nest_survival_reals_FP_season$season <- 
  as.numeric(str_sub(nest_survival_reals_FP_season$X2, 2, 5))
nest_survival_reals_FP_season$season <- paste(nest_survival_reals_FP_season$season, nest_survival_reals_FP_season$season + 1, sep = " - ")
nest_survival_reals_FP_season <- 
  nest_survival_reals_FP_season %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_season) <- NULL

nest_survival_reals_MP_season <- 
  nest_survival_run_MP[[46]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_season), " ", n = 4))
nest_survival_reals_MP_season <- cbind(Groups, nest_survival_reals_MP_season)
nest_survival_reals_MP_season$season <- 
  as.numeric(str_sub(nest_survival_reals_MP_season$X2, 2, 5))
nest_survival_reals_MP_season$season <- paste(nest_survival_reals_MP_season$season, nest_survival_reals_MP_season$season + 1, sep = " - ")
nest_survival_reals_MP_season <- 
  nest_survival_reals_MP_season %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_season) <- NULL

nest_survival_reals_BSC_season <- 
  nest_survival_run_BSC[[46]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_season), " ", n = 4))
nest_survival_reals_BSC_season <- cbind(Groups, nest_survival_reals_BSC_season)
nest_survival_reals_BSC_season$season <- 
  as.numeric(str_sub(nest_survival_reals_BSC_season$X2, 2, 5))
nest_survival_reals_BSC_season$season <- paste(nest_survival_reals_BSC_season$season, nest_survival_reals_BSC_season$season + 1, sep = " - ")
nest_survival_reals_BSC_season <- 
  nest_survival_reals_BSC_season %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_season) <- NULL

nest_survival_reals_season <- 
  bind_rows(nest_survival_reals_FP_season, 
            nest_survival_reals_MP_season, 
            nest_survival_reals_BSC_season)

ggplot() +
  geom_line(data = nest_survival_reals_season, 
            aes(x = season, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2) +
  geom_errorbar(data = nest_survival_reals_season, 
                aes(ymin = lcl, ymax = ucl, 
                    x = season, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_season, 
             aes(x = season, y = estimate, fill = region),
             shape = 21, size = 2, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
  xlab("season") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.7, 1)) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(region ~ ., labeller = as_labeller(region_names))

Variation within years

Code
# Extract estimates of survival from Cubic model with management 
# (non-linear season variation and management effect)
nest_survival_reals_MP <- 
  nest_survival_run_MP[[1]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP), " ", n = 4))
nest_survival_reals_MP <- cbind(Groups, nest_survival_reals_MP)
nest_survival_reals_MP$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_MP$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_MP$region = "MP"

nest_survival_reals_BSC <- 
  nest_survival_run_BSC[[1]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC), " ", n = 4))
nest_survival_reals_BSC <- cbind(Groups, nest_survival_reals_BSC)
nest_survival_reals_BSC$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_BSC$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_BSC$region = "BSC"

nest_survival_reals_FP <- 
  nest_survival_run_FP[[1]]$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP), " ", n = 4))
nest_survival_reals_FP <- cbind(Groups, nest_survival_reals_FP)
nest_survival_reals_FP$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_FP$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_FP$region = "FP"

nest_survival_reals <- 
  bind_rows(nest_survival_reals_MP, nest_survival_reals_BSC, nest_survival_reals_MP) %>% 
  dplyr::select(region, day_of_season, estimate, lcl, ucl)
row.names(nest_survival_reals) <- NULL

# FP
dates_for_plot_FP <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_FP$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_FP$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_FP$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_FP$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_FP$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_FP$nest_data.processed$data$FirstFound)))))

nest_survival_reals_dates_FP <- 
  left_join(nest_survival_reals_FP, dates_for_plot_FP, by = "day_of_season")

nest_survival_season_plot_FP <- 
  ggplot(data = nest_survival_reals_dates_FP) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))

nest_discovery_season_plot_FP <- 
      ggplot(RMark_data_FP$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_FP$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_FP$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_FP <- 
  nest_discovery_season_plot_FP / 
  nest_survival_season_plot_FP +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Fleurieu Peninsula")

### MP ----
dates_for_plot_MP <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_MP$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_MP$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_MP$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_MP$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_MP$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_MP$nest_data.processed$data$FirstFound)))))

nest_survival_reals_dates_MP <- 
  left_join(nest_survival_reals_MP, dates_for_plot_MP, by = "day_of_season")

nest_survival_season_plot_MP <- 
  ggplot(data = nest_survival_reals_dates_MP) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))

nest_discovery_season_plot_MP <- 
      ggplot(RMark_data_MP$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_MP$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_MP$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_MP <- 
  nest_discovery_season_plot_MP / 
  nest_survival_season_plot_MP +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Mornington Peninsula")

### BSC ----
dates_for_plot_BSC <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_BSC$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_BSC$nest_data.processed$data$FirstFound)))))

nest_survival_reals_dates_BSC <- 
  left_join(nest_survival_reals_BSC, dates_for_plot_BSC, by = "day_of_season")

nest_survival_season_plot_BSC <- 
  ggplot(data = nest_survival_reals_dates_BSC) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))

nest_discovery_season_plot_BSC <- 
      ggplot(RMark_data_BSC$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_BSC$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_BSC$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_BSC <- 
  nest_discovery_season_plot_BSC / 
  nest_survival_season_plot_BSC +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Bellarine / Surf Coast")

hooded_plover_nest_plot_FP

Code
hooded_plover_nest_plot_MP

Code
hooded_plover_nest_plot_BSC

Explore correlations between “Fun days” and the threats

We can see in our model selection of nest survival all three sites that our variable “fun days” (a measure of the number of weekends or holidays a nest is exposed to) was the best at explaining variation in daily nest survival. To interpret this effect, it essentially means that if a nest is initiated on, for example, a Friday right before a long period of consecutive holidays, this nest is expected to have extremely low survival compared to a nest initiated on, for example, a Monday at the early or late part of the season when there are no holidays.

Despite “fun days” having such a strong relationship to daily nest survival, our threat variables (e.g., maximum number of dogs off leash counted, maximum number of humans counted, etc.) all showed little relationship with daily nest survival, which we interpret as a methodological effect: the surveys conducted to quantify specific threats were too infrequent to capture a meaningful measure of the pressure that these threats have on nest survival. To link “Fun days” to the threats, we here do an exploratory relationship between fundays and the threats.

Code
library(lme4)
library(gtsummary)
library(ggeffects)
library(effects)

threat_data__scaled_FP <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "FP") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))

threat_data__scaled_MP <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "MP") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))

threat_data__scaled_BSC <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "BSC") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))

Humans and fun days relationships at the three regions

strong relationship between the number of humans detected and the occurrence of a weekend or a holiday at all 3 regions

Code
humans_fun_day_FP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          humans_ + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "binomial")

humans_fun_day_MP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          humans_ + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "binomial")

humans_fun_day_BSC <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          humans_ + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "binomial")

Fleurieu Peninsula

Code
tbl_regression(humans_fun_day_FP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.34 -0.44, -0.24 <0.001
obs_date2
    obs_date2 10 5.8, 14 <0.001
    obs_date2² -44 -48, -39 <0.001
    obs_date2³ -9.8 -14, -5.3 <0.001
humans_ 0.06 0.05, 0.06 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Mornington Peninsula

Code
tbl_regression(humans_fun_day_MP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -1.4 -1.6, -1.2 <0.001
obs_date2
    obs_date2 13 7.3, 18 <0.001
    obs_date2² -25 -31, -20 <0.001
    obs_date2³ 9.4 3.8, 15 0.001
humans_ 0.05 0.05, 0.06 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Bellarine / Surf Coast

Code
tbl_regression(humans_fun_day_BSC, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.47 -0.60, -0.34 <0.001
obs_date2
    obs_date2 10 5.8, 15 <0.001
    obs_date2² -29 -34, -24 <0.001
    obs_date2³ -6.2 -12, -0.88 0.022
humans_ 0.07 0.06, 0.08 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Dogs and fun days relationships at the three regions

strong relationship between the number of dogs detected and the occurrence of a weekend or a holiday at all 3 regions

Code
dogs_fun_day_FP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          dogs_ + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "binomial")

dogs_fun_day_MP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          dogs_ + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "binomial")

dogs_fun_day_BSC <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          dogs_ + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "binomial")

Fleurieu Peninsula

Code
tbl_regression(dogs_fun_day_FP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.22 -0.31, -0.12 <0.001
obs_date2
    obs_date2 13 8.2, 17 <0.001
    obs_date2² -45 -50, -41 <0.001
    obs_date2³ -12 -16, -7.4 <0.001
dogs_ 0.11 0.09, 0.12 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Mornington Peninsula

Code
tbl_regression(dogs_fun_day_MP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -1.3 -1.5, -1.1 <0.001
obs_date2
    obs_date2 16 11, 21 <0.001
    obs_date2² -29 -35, -24 <0.001
    obs_date2³ 9.8 4.2, 15 <0.001
dogs_ 0.21 0.15, 0.26 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Bellarine / Surf Coast

Code
tbl_regression(dogs_fun_day_BSC, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.39 -0.52, -0.26 <0.001
obs_date2
    obs_date2 13 8.3, 18 <0.001
    obs_date2² -31 -36, -26 <0.001
    obs_date2³ -8.6 -14, -3.1 0.002
dogs_ 0.17 0.14, 0.20 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Dogs off leashes and fun days relationships at the three regions

strong relationship between the number of dogs off leash detected and the occurrence of a weekend or a holiday at all 3 regions

Code
dogs_off_fun_day_FP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          dogs_off_ + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "binomial")

dogs_off_fun_day_MP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          dogs_off_ + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "binomial")

dogs_off_fun_day_BSC <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          dogs_off_ + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "binomial")

Fleurieu Peninsula

Code
tbl_regression(dogs_off_fun_day_FP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.16 -0.25, -0.06 0.002
obs_date2
    obs_date2 13 8.2, 17 <0.001
    obs_date2² -48 -52, -43 <0.001
    obs_date2³ -12 -17, -7.9 <0.001
dogs_off_ 0.10 0.08, 0.11 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Mornington Peninsula

Code
tbl_regression(dogs_off_fun_day_MP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -1.3 -1.5, -1.0 <0.001
obs_date2
    obs_date2 16 11, 21 <0.001
    obs_date2² -30 -35, -24 <0.001
    obs_date2³ 9.9 4.3, 15 <0.001
dogs_off_ 0.18 0.12, 0.25 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Bellarine / Surf Coast

Code
tbl_regression(dogs_off_fun_day_BSC, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.33 -0.45, -0.20 <0.001
obs_date2
    obs_date2 14 9.3, 19 <0.001
    obs_date2² -32 -37, -27 <0.001
    obs_date2³ -9.4 -15, -3.9 <0.001
dogs_off_ 0.17 0.13, 0.21 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Ravens and Magpies and fun days relationships at the three regions

no relationship (but slightly negative) between the number of corvids detected and the occurrence of a weekend or a holiday at all 3 regions

Code
pred_birds_fun_day_FP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          pred_birds_ + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "binomial")

pred_birds_fun_day_MP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          pred_birds_ + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "binomial")

pred_birds_fun_day_BSC <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          pred_birds_ + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "binomial")

Fleurieu Peninsula

Code
tbl_regression(pred_birds_fun_day_FP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.04 -0.13, 0.06 0.5
obs_date2
    obs_date2 13 8.5, 17 <0.001
    obs_date2² -48 -53, -43 <0.001
    obs_date2³ -14 -19, -9.8 <0.001
pred_birds_ -0.05 -0.07, -0.02 0.001
1 OR = Odds Ratio, CI = Confidence Interval

Mornington Peninsula

Code
tbl_regression(pred_birds_fun_day_MP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -1.2 -1.4, -0.99 <0.001
obs_date2
    obs_date2 16 11, 21 <0.001
    obs_date2² -31 -36, -26 <0.001
    obs_date2³ 10 4.6, 16 <0.001
pred_birds_ -0.08 -0.12, -0.03 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Bellarine / Surf Coast

Code
tbl_regression(pred_birds_fun_day_BSC, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.18 -0.31, -0.05 0.007
obs_date2
    obs_date2 14 9.0, 18 <0.001
    obs_date2² -31 -37, -26 <0.001
    obs_date2³ -9.2 -15, -3.8 <0.001
pred_birds_ -0.02 -0.06, 0.02 0.4
1 OR = Odds Ratio, CI = Confidence Interval

Gulls and fun days relationships at the three regions

no relationship (but slightly negative) between the number of corvids detected and the occurrence of a weekend or a holiday at all 3 regions

Code
gulls_fun_day_FP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          gulls_ + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "binomial")

gulls_fun_day_MP <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          gulls_ + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "binomial")

gulls_fun_day_BSC <-
  glmer(cbind(fun, no_fun) ~ 
          poly(obs_date2, 3) + 
          gulls_ + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "binomial")

Fleurieu Peninsula

Code
tbl_regression(gulls_fun_day_FP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.06 -0.16, 0.04 0.3
obs_date2
    obs_date2 12 8.2, 17 <0.001
    obs_date2² -48 -52, -43 <0.001
    obs_date2³ -14 -18, -9.6 <0.001
gulls_ -0.01 -0.02, 0.01 0.3
1 OR = Odds Ratio, CI = Confidence Interval

Mornington Peninsula

Code
tbl_regression(gulls_fun_day_MP, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -1.2 -1.4, -0.99 <0.001
obs_date2
    obs_date2 16 11, 21 <0.001
    obs_date2² -30 -36, -25 <0.001
    obs_date2³ 9.8 4.2, 15 <0.001
gulls_ -0.06 -0.09, -0.03 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Bellarine / Surf Coast

Code
tbl_regression(gulls_fun_day_BSC, intercept = TRUE)
Characteristic log(OR)1 95% CI1 p-value
(Intercept) -0.18 -0.31, -0.06 0.005
obs_date2
    obs_date2 14 8.9, 18 <0.001
    obs_date2² -31 -37, -26 <0.001
    obs_date2³ -9.8 -15, -4.4 <0.001
gulls_ -0.02 -0.03, 0.00 0.084
1 OR = Odds Ratio, CI = Confidence Interval